﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using cfg = System.Configuration;
using System.Collections;
using GoldPrinter;
using WeifenLuo.WinFormsUI.Docking;
namespace BYManageInfoSystem
{
    public partial class Frm_SeaGateFillBoxSheet : DockContent
    {
        private DGBY.BLL.BYBackQingDanTab m_bllBYBackQingDanTab = new DGBY.BLL.BYBackQingDanTab();

        private int m_nSelectedGuiXingIndex = 5;
        private DataSet m_dsPaidan = new DataSet();
        //private DGBY.BLL.FeeZXZTruePayTab m_bllFeeZXZTruePayTab = new DGBY.BLL.FeeZXZTruePayTab();
        //private DGBY.BLL.FeeJCFTruePayTab m_bllFeeJCFTruePayTab = new DGBY.BLL.FeeJCFTruePayTab();
        private DGBY.BLL.FeeDZTruePayTab m_bllFeeDZTruePayTab = new DGBY.BLL.FeeDZTruePayTab();
        private DGBY.BLL.HxdNoTab m_bllHxdNoTab = new DGBY.BLL.HxdNoTab();
        private DGBY.BLL.FeeHKYSTruePayTab m_bllFeeHKYSTruePayTab = new DGBY.BLL.FeeHKYSTruePayTab();
        private DGBY.BLL.FeeDHLTruePayTab m_bllFeeDHLTruePayTab = new DGBY.BLL.FeeDHLTruePayTab();

        private DGBY.BLL.FeeHKCWTruePayTab m_bllFeeHKCWTruePayTab = new DGBY.BLL.FeeHKCWTruePayTab();

        private DGBY.BLL.FeeBGTruePayTab m_bllFeeBGTruePayTab = new DGBY.BLL.FeeBGTruePayTab();
        private DGBY.BLL.FeeDLCWTruePayTab m_bllFeeDLCWTruePayTab = new DGBY.BLL.FeeDLCWTruePayTab();

        private DGBY.BLL.FacFeeTabNew m_bllFacFeeTabNew = new DGBY.BLL.FacFeeTabNew();
        //private DGBY.BLL.FacFeeRelationTab m_bllFacFeeRelationTab = new DGBY.BLL.FacFeeRelationTab();
        // private DGBY.BLL.FacFeeTab m_bllFacFeeTab = new DGBY.BLL.FacFeeTab();
        private DGBY.BLL.FeeTab m_bllFeeTab = new DGBY.BLL.FeeTab();
        private bool m_bInsertFlag = false;
        private int m_nDelIndex = -1;
       //private bool m_bFlag = false;
        private DGBY.BLL.FactoryGoodsTab m_bllFactoryGoodsTab = new DGBY.BLL.FactoryGoodsTab();
        private DGBY.BLL.FinCheckInvoiceRecordDetailTab_New m_bllFinCheckInvoiceRecordDetailTab_New = new DGBY.BLL.FinCheckInvoiceRecordDetailTab_New();
        private DGBY.BLL.FinInvoiceRecordTab_New m_bllFinInvoiceRecordTab_New = new DGBY.BLL.FinInvoiceRecordTab_New();
        //private DGBY.BLL.HxdNoTab m_bllHxdNoTab = new DGBY.BLL.HxdNoTab();
        private DGBY.BLL.TYInvoiceTab m_bllTYInvoiceTab = new DGBY.BLL.TYInvoiceTab();
        private DGBY.BLL.BGCKHTTab m_bllBGCKHTTab = new DGBY.BLL.BGCKHTTab();
        private DGBY.BLL.SJCKHTTab m_bllSJCKHTTab = new DGBY.BLL.SJCKHTTab();
        public static DGBY.BLL.TaoDaPrinterNameTab bllTaoDaPrinterNameTab = new DGBY.BLL.TaoDaPrinterNameTab();
        private DGBY.BLL.SJPackGoodsMXTab m_bllSJPackGoodsMXTab = new DGBY.BLL.SJPackGoodsMXTab();
        private DGBY.BLL.SJPackingTab m_bllSJPackingTab = new DGBY.BLL.SJPackingTab();
        private DGBY.BLL.NumDanWeiTab m_bllNumDanWeiTab = new DGBY.BLL.NumDanWeiTab();
        private DGBY.BLL.BiZhiTab m_bllBiZhiTab = new DGBY.BLL.BiZhiTab();
        private DGBY.BLL.BGHDataTab m_bllBGHDataTab = new DGBY.BLL.BGHDataTab();
        private DGBY.BLL.BYCompanyTab m_bllBYCompanyTab = new DGBY.BLL.BYCompanyTab();
        private DGBY.BLL.PaidanRegisterTab m_bllPaidanRegisterTab = new DGBY.BLL.PaidanRegisterTab();
        private DGBY.BLL.SHCompTab m_bllSHCompTab = new DGBY.BLL.SHCompTab();
        private DGBY.BLL.ZYHarborTab m_bllZYHarborTab = new DGBY.BLL.ZYHarborTab();
        private DGBY.BLL.BGHarborTab m_bllBGHarborTab = new DGBY.BLL.BGHarborTab();

        private DGBY.BLL.QYCountryTab m_bllQYCountryTab = new DGBY.BLL.QYCountryTab();
        private DGBY.BLL.BZSortTab m_bllBZSortTab = new DGBY.BLL.BZSortTab();
        private DGBY.BLL.BGPackingTab m_bllBGPackingTab = new DGBY.BLL.BGPackingTab();
        private DGBY.BLL.GuiXingTab m_bllGuiXingTab = new DGBY.BLL.GuiXingTab();
        private DGBY.BLL.BGPackGoodsMXTab m_bllBGPackGoodsMXTab = new DGBY.BLL.BGPackGoodsMXTab();
        private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
     //   private DGBY.BLL.BGDComeBackTab m_bllBGDComeBackTab = new DGBY.BLL.BGDComeBackTab();
      //  DateTime m_dtShenBaoDate = new DateTime();
        private DGBY.BLL.LogRecTab m_bllLogRecTab = new DGBY.BLL.LogRecTab();
        private DGBY.BLL.DG_BackRecoveryMaterialResgistTab m_bllBackRecoveryMaterialResgistTab = new DGBY.BLL.DG_BackRecoveryMaterialResgistTab();
        private DGBY.BLL.PaiCheTabNew m_bllPaiCheTabNew = new DGBY.BLL.PaiCheTabNew();

        Hashtable m_SQLStringList = new Hashtable();
        ArrayList m_arrayList = new ArrayList();
        private int m_nSelectBGPackGoodsMXTabID = 0;
        private int m_nSelectBGPackingTabID = 0;

        protected string templetFilePath = cfg.ConfigurationSettings.AppSettings["TempletFilePath"];
        //ExcelBase eB = new ExcelBase();

        public Frm_SeaGateFillBoxSheet()
        {
            InitializeComponent();
        }

        private void InitContractNoCombox()
        {
            //DataSet ds = m_bllPaidanRegisterTab.GetAllPaiDanList("");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    this.comboBoxContractNo.DataSource = ds.Tables[0];
            //    this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
            //    this.comboBoxContractNo.DisplayMember = "合同编号";
            //    this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
            //    this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            //    this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
            //}


            try
            {
                if (Frm_Main.m_nContractSelectValue == 127)
                    return;
                DataRow[] drs = m_dsPaidan.Tables[0].Select("PaidanRegisterTabID = '" + Frm_Main.m_nContractSelectValue.ToString() + "'");
                if (drs.Length > 0)
                    this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                else
                {
                    m_dsPaidan = m_bllPaidanRegisterTab.GetNameAndIDAll("");
                    if (m_dsPaidan.Tables.Count > 0 && m_dsPaidan.Tables[0].Rows.Count > 0)
                    {
                        this.comboBoxContractNo.DataSource = m_dsPaidan.Tables[0];
                        this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                        this.comboBoxContractNo.DisplayMember = "合同编号";
                        this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                        this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                        this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                    }

                    this.comboBoxRecvGoodsComp.SelectedIndex = 0;

                    this.comboBoxStartCountry.SelectedIndex = 0;

                    this.comboBoxPort.SelectedIndex = 0;
                    this.comboBoxBGPort.SelectedIndex = 0;
                    this.comboBoxOutSideCate.SelectedIndex = 0;
                    this.comboBoxBGH.SelectedIndex = 0;
                    

                    this.comboBoxCoinUnit2.SelectedIndex = 0;
                    this.comboBoxBoxCate.SelectedIndex = m_nSelectedGuiXingIndex;
                }
            }
            catch (System.Exception ex)
            {
                //  MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        private void InitCombox()
        {
            m_dsPaidan = m_bllPaidanRegisterTab.GetNameAndID("");
            if (m_dsPaidan.Tables.Count > 0 && m_dsPaidan.Tables[0].Rows.Count > 0)
            {
                this.comboBoxContractNo.DataSource = m_dsPaidan.Tables[0];
                this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                this.comboBoxContractNo.DisplayMember = "合同编号";
                this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
            }
            DataSet ds = m_bllSHCompTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxRecvGoodsComp.DataSource = ds.Tables[0];
                this.comboBoxRecvGoodsComp.DisplayMember = "公司名字";
                this.comboBoxRecvGoodsComp.ValueMember = "SHCompTabID";
                this.comboBoxRecvGoodsComp.SelectedIndex = 0;
            }

            ds = m_bllQYCountryTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxStartCountry.DataSource = ds.Tables[0];
                this.comboBoxStartCountry.DisplayMember = "起运国";
                this.comboBoxStartCountry.ValueMember = "QYCountryTabID";
                this.comboBoxStartCountry.SelectedIndex = 0;
            }

            ds = m_bllZYHarborTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxPort.DataSource = ds.Tables[0];
                this.comboBoxPort.DisplayMember = "装运港名称";
                this.comboBoxPort.ValueMember = "ZYHarborTabID";
                this.comboBoxPort.SelectedIndex = 0;
            }
            ds = m_bllBGHarborTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxBGPort.DataSource = ds.Tables[0];
                this.comboBoxBGPort.DisplayMember = "报关港";
                this.comboBoxBGPort.ValueMember = "BGHarborTabID";
                this.comboBoxBGPort.SelectedIndex = 0;
            }
            ds = m_bllBZSortTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxOutSideCate.DataSource = ds.Tables[0];
                this.comboBoxOutSideCate.DisplayMember = "包装种类";
                this.comboBoxOutSideCate.ValueMember = "BZSortTabID";
                this.comboBoxOutSideCate.SelectedIndex = 0;
            }

            ds = m_bllBiZhiTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxCoinUnit2.DataSource = ds.Tables[0];
                this.comboBoxCoinUnit2.DisplayMember = "币制名称";
                this.comboBoxCoinUnit2.ValueMember = "BiZhiTabID";
                this.comboBoxCoinUnit2.SelectedIndex = 0;
            }
            ds = m_bllBGHDataTab.GetListWithAddrEx("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxBGH.DataSource = ds.Tables[0];
                this.comboBoxBGH.DisplayMember = "报关行简称";
                this.comboBoxBGH.ValueMember = "BGHDataTabID";
                this.comboBoxBGH.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxBGH.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxBGH.SelectedIndex = 0;
            }
            //ds = m_bllNumDanWeiTab.GetList("");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    this.comboBoxUnit.DataSource = ds.Tables[0];
            //    this.comboBoxUnit.DisplayMember = "单位名称";
            //    this.comboBoxUnit.ValueMember = "NumDanWeiTabID";
            //    this.comboBoxUnit.SelectedIndex = 0;
            //}

            ds = m_bllGuiXingTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxBoxCate.DataSource = ds.Tables[0];
                this.comboBoxBoxCate.DisplayMember = "柜型";
                this.comboBoxBoxCate.ValueMember = "GuiXingTabID";
                //int i = 0;
                //for(i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{
                //    string strTemp = ds.Tables[0].Rows[i]["柜型"].ToString();

                //    if(strTemp == "40HQ")
                //    {
                //       m_nSelectedGuiXingIndex = i;
                //       break;
                //    }

                //}
                this.comboBoxBoxCate.SelectedIndex = m_nSelectedGuiXingIndex;
            }
            

        }

        private void Frm_SeaGateFillBoxSheet_Load(object sender, EventArgs e)
        {
            this.groupBoxGoodsDetail.Visible = false;
            //InitQueryCondition();
            InitCombox();

        }

        private void ShowAllFillBoxSheet(string strWhere)
        {
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec(strWhere);

            ultraGrid1.DataSource = null;
            ultraGrid2.DataSource = null;
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxPort.Text = m_ds.Tables[0].Rows[0]["装运港"].ToString();
                this.comboBoxBGPort.Text = m_ds.Tables[0].Rows[0]["报关港"].ToString();
                ultraGrid1.DataSource = m_ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            }
        }

        private void ShowFillBoxSheetByContractCode(string strContractCode)
        {
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + strContractCode + "'");

            ultraGrid1.DataSource = null;
            ultraGrid2.DataSource = null;
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                m_nSelectBGPackingTabID = Convert.ToInt32(m_ds.Tables[0].Rows[0]["BGPackingTabID"].ToString());
                //this.textBoxSecondSheetNo.Text = m_ds.Tables[0].Rows[0]["单据号"].ToString();
                //this.comboBoxPort.Text = m_ds.Tables[0].Rows[0]["装运港"].ToString();
                //this.comboBoxBGPort.Text = m_ds.Tables[0].Rows[0]["报关港"].ToString();
                cellBGPackingTabClick();
                ultraGrid1.DataSource = m_ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            }
            else
            {
                DataSet ds = m_bllBYBackQingDanTab.GetBackQingInfo("ContractCode = '" + strContractCode + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strTemp = ds.Tables[0].Rows[0]["出口方式"].ToString();
                    if (strTemp == "东莞转关入深圳仓" || strTemp == "东莞整柜转关深圳还柜")
                    {
                        this.comboBoxPort.SelectedValue = 2;
                    }

                }
                this.comboBoxBoxCate.SelectedIndex = m_nSelectedGuiXingIndex;
                m_nSelectBGPackingTabID = 0;
                this.textBoxSecondSheetNo.Text = "";
                this.textBoxGoodsBoxNum.Text = "";
                this.textBoxClosePaperNo.Text = "";
            }


        }
        private void comboBoxContractNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string str = this.comboBoxContractNo.SelectedValue.ToString();
                int nID = Convert.ToInt32(str, 10);
                DataSet ds = m_bllPaidanRegisterTab.GetList("PaidanRegisterTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nCompId = Convert.ToInt32(ds.Tables[0].Rows[0]["BYCompanyTabID"].ToString(), 10);
                    DataSet ds1 = m_bllBYCompanyTab.GetList("BYCompanyTabID = '" + nCompId + "'");
                    if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                    {
                        this.textBoxCompany.Text = ds1.Tables[0].Rows[0]["经营单位名称"].ToString();
                    }
                }

                string strContractCode = ds.Tables[0].Rows[0]["ContractCode"].ToString();
               // this.textBox1ContractNoGoodsDetail.Text = strContractCode;
                ShowFillBoxSheetByContractCode(strContractCode);
                //this.textBoxMark.Text = "";
                //this.textBoxNote.Text = "";

            }
            catch { }
        }



        private void cellBGPackingTabClick()
        {
            this.ultraGrid1.Dock = DockStyle.None;
            this.groupBoxGoodsDetail.Visible = true;
            DGBY.Model.BGPackingTab modelBGPackingTab = m_bllBGPackingTab.GetModel(m_nSelectBGPackingTabID);
            if (modelBGPackingTab != null)
            {
                this.textBoxNote.Text = modelBGPackingTab.Note;
                this.textBoxSecondSheetNo.Text = modelBGPackingTab.BGPackDJNo.ToString();
                this.textBoxMark.Text = modelBGPackingTab.ShoeBrand;
                this.textBoxMaiTou.Text = modelBGPackingTab.ShipMarks;
                this.textBoxSelectShipNo.Text = modelBGPackingTab.DingCangNo;
             //   this.textBoxShipName.Text = modelBGPackingTab.ShipName;
                this.textBoxShipSequence.Text = modelBGPackingTab.HangCi;
                this.textBoxGoodsBoxNum.Text = modelBGPackingTab.GuiNo;
                this.textBoxClosePaperNo.Text = modelBGPackingTab.FengTiao;
                //this.textBoxContractNo.Text = modelBGPackingTab.ContractCode;
                if (modelBGPackingTab.BiZhiTabID != null)
                    this.comboBoxCoinUnit2.SelectedValue = modelBGPackingTab.BiZhiTabID;
                if (modelBGPackingTab.SHCompTabID != null)
                    this.comboBoxRecvGoodsComp.SelectedValue = modelBGPackingTab.SHCompTabID;
                if (modelBGPackingTab.QYCountryTabID != null)
                    this.comboBoxStartCountry.SelectedValue = modelBGPackingTab.QYCountryTabID;
                if (modelBGPackingTab.ZYHarborTabID != null)
                    this.comboBoxPort.SelectedValue = modelBGPackingTab.ZYHarborTabID;
                if (modelBGPackingTab.BGHarborTabID != null)
                    this.comboBoxBGPort.SelectedValue = modelBGPackingTab.BGHarborTabID;
                if (modelBGPackingTab.BZSortTabID != null)
                    this.comboBoxOutSideCate.SelectedValue = modelBGPackingTab.BZSortTabID;
                if (modelBGPackingTab.PaidanRegisterTabID != null)
                    this.comboBoxContractNo.SelectedValue = modelBGPackingTab.PaidanRegisterTabID;
                if (modelBGPackingTab.GuiXingTabID != null)
                    this.comboBoxBoxCate.SelectedValue = modelBGPackingTab.GuiXingTabID;
                if (modelBGPackingTab.BGHDataTabID != null)
                    this.comboBoxBGH.SelectedValue = modelBGPackingTab.BGHDataTabID;
                if (modelBGPackingTab.IsShoePack == "否")
                {
                    this.checkBoxIsShoe.Checked = false;
                    this.textBoxMark.ReadOnly = true;
                }
                else
                {
                    this.checkBoxIsShoe.Checked = true;
                    this.textBoxMark.ReadOnly = false;
                }

                //this.textBoxDJNo.Text = modelBGPackingTab.BGPackDJNo.ToString();
                ShowAllMXRecordInDataGridView(m_nSelectBGPackingTabID);

                //DataSet ds = m_bllHxdNoTab.GetList("PaidanRegisterTabID = '" + modelBGPackingTab.PaidanRegisterTabID.ToString() + "'");
                //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                //{
                //    m_dtShenBaoDate = (System.DateTime)ds.Tables[0].Rows[0]["SBDate"];
                //    this.buttonInGoodsPrint.Enabled = true;
                //    this.buttonInGoodsPrintPreview.Enabled = true;
                //}
                //else
                //{
                //    this.buttonInGoodsPrint.Enabled = false;
                //    this.buttonInGoodsPrintPreview.Enabled = false;
                //}
            }
            else
            {
                this.textBoxNote.Text = "";
                this.textBoxSecondSheetNo.Text = "";
                this.textBoxMark.Text = "";
                this.textBoxMaiTou.Text = "";
            }
        }



        private Int64 MakeBGPackDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllBGPackingTab.GetSJPackDJNoByDate("BGPackDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        private Int64 MakeBGContractDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllBGCKHTTab.GetBGPackDJNoByDate("BGCKHTDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxBGDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        //增加报关出口合同记录
        private void AddOneBGCKContractRec(int nPaidanRegisterTabID, bool bIsDisCount, ref int nYSMethodTabID)
        {
            try
            {
                DataSet ds = m_bllBGCKHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return;
                }
                DGBY.Model.BGCKHTTab modelBGCKHTTab = new DGBY.Model.BGCKHTTab();
                ds = m_bllPaidanRegisterTab.GetTransWay("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    modelBGCKHTTab.YSMethodTabID = (int)ds.Tables[0].Rows[0]["YSMethodTabID"];
                }
                modelBGCKHTTab.isDisCount = bIsDisCount;
                modelBGCKHTTab.JYCompDaiBiao = "";
                modelBGCKHTTab.SHCompDaiBiao = "";
                modelBGCKHTTab.DYZ = "";
                modelBGCKHTTab.BaoXian = "由买方负责投保。";
                modelBGCKHTTab.FKCondition = "卖方发货后120天内电汇付款。";
                modelBGCKHTTab.SPCheck = "由卖方申请，并保证按商检部门规定执行。";
                modelBGCKHTTab.ZYMethod = "由双方协商解决或交由签约地有管辖权法院裁决。";
                modelBGCKHTTab.SCPiNo = "";
                modelBGCKHTTab.QTThing = "由双方协商解决。";
                modelBGCKHTTab.Note = "";

                modelBGCKHTTab.BGCKHTDJNo = MakeBGContractDJNo();

                //modelBGCKHTTab.QDDate = this.dateTimePickerMakeProtocolDate.Value;
                //modelBGCKHTTab.JHDate = this.dateTimePickerDeadLine.Value;
                modelBGCKHTTab.QDDate = System.DateTime.Now.Date;
                modelBGCKHTTab.JHDate = System.DateTime.Now.Date;
                modelBGCKHTTab.BGCKHTDJDate = System.DateTime.Now.Date;

                modelBGCKHTTab.InvoiceNo = "";
                modelBGCKHTTab.InvoiceNote = "";

                modelBGCKHTTab.QDPlaceTabID = 1;

                //modelBGCKHTTab.YSMethodTabID = 1;

                modelBGCKHTTab.MDCountryTabID = 1;

                modelBGCKHTTab.JNHYPosTabID = 1;

                modelBGCKHTTab.PaidanRegisterTabID = nPaidanRegisterTabID;

                modelBGCKHTTab.ZYHarborTabID = 1;

                modelBGCKHTTab.SHCompTabID = 1;

                modelBGCKHTTab.BZSortTabID = 1;

                ds = m_bllBYBackQingDanTab.GetBackQingInfoByID("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strTemp = ds.Tables[0].Rows[0]["出口方式"].ToString();
                    if (strTemp == "只到香港不再出口")
                    {
                        modelBGCKHTTab.MDCountryTabID = 23;
                    }

                }
                m_bllBGCKHTTab.TransAdd(modelBGCKHTTab, m_SQLStringList, m_arrayList);

                nYSMethodTabID = modelBGCKHTTab.YSMethodTabID;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        //增加回收报关单记录
        //private void AddOneBackBGDRec(int nPaidanRegisterTabID)
        //{
        //    try
        //    {
        //        DataSet ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //        {
        //            return;
        //        }
        //        //回收报关单
        //        DGBY.Model.BGDComeBackTab modelBGDComeBackTab = new DGBY.Model.BGDComeBackTab();

        //        modelBGDComeBackTab.BGDNo = "";
        //        modelBGDComeBackTab.FHDWName = "";
        //        modelBGDComeBackTab.PZWH = "";
        //        modelBGDComeBackTab.TotalPieceNum = "0";
        //        modelBGDComeBackTab.TotalMaoWeight = "0";
        //        modelBGDComeBackTab.TotalJingWeight = "0";
        //        modelBGDComeBackTab.SFDZName = "";
        //        modelBGDComeBackTab.SFDZNo = "";
        //        modelBGDComeBackTab.Note = "";
        //        modelBGDComeBackTab.KaiPiaoHuiLv = 0;

        //        modelBGDComeBackTab.SBDate = System.DateTime.Now.Date;
        //        modelBGDComeBackTab.CKouDate = System.DateTime.Now.Date;


        //        modelBGDComeBackTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //        modelBGDComeBackTab.YSMethodTabID = 1;
        //        modelBGDComeBackTab.MDCountryTabID = 1;
        //        modelBGDComeBackTab.JNHYPosTabID = 1;
        //        modelBGDComeBackTab.ChengJFSTabID = 1;
        //        modelBGDComeBackTab.MDPortTabID = 1;
        //        modelBGDComeBackTab.BZSortTabID = 1;
        //        modelBGDComeBackTab.BGHDataTabID = 1;
        //        modelBGDComeBackTab.HaiGuanTabID = 1;
        //        modelBGDComeBackTab.MaoYiFSTabID = 1;
        //        modelBGDComeBackTab.JieHuiFSTabID = 1;
        //        modelBGDComeBackTab.ZhengMXZTabID = 1;
        //        modelBGDComeBackTab.IsSyncComplete = 1;
        //        modelBGDComeBackTab.BiZhiTabID = 1;

        //        m_bllBGDComeBackTab.Add(modelBGDComeBackTab);



        //    }
        //    catch (System.Exception ex)
        //    {
        //        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        //    }
        //}
        private Int64 MakeRecvMoneyDetailDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllFinCheckInvoiceRecordDetailTab_New.GetSJPackDJNoByDate("DanJuDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        private void AddFinCheckInvoiceRecordDetailTabNewAfterTrans(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFinCheckInvoiceRecordDetailTab_New.GetList("FinCheckInvoiceRecordDetailTab_New.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            DGBY.Model.FinCheckInvoiceRecordDetailTab_New modelFinCheckInvoiceRecordDetailTab_New = new DGBY.Model.FinCheckInvoiceRecordDetailTab_New();
            modelFinCheckInvoiceRecordDetailTab_New.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFinCheckInvoiceRecordDetailTab_New.ShenPiaoDate = null; 
            modelFinCheckInvoiceRecordDetailTab_New.DanJuDate = null;
            modelFinCheckInvoiceRecordDetailTab_New.TuiPiaoReason = "";
            modelFinCheckInvoiceRecordDetailTab_New.Note = "";
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent17 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent16 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent15 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent13 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent9 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent5 = 0;

            modelFinCheckInvoiceRecordDetailTab_New.HKPercent17 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent16 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent15 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent13 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent9 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent5 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKHuiLv = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDHuiLv = 0;
            modelFinCheckInvoiceRecordDetailTab_New.IsPayTaxDone = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDJinE = 0;
            modelFinCheckInvoiceRecordDetailTab_New.SetPercent = (decimal)0.17;
            modelFinCheckInvoiceRecordDetailTab_New.TransGongShi = "";
            modelFinCheckInvoiceRecordDetailTab_New.BianHao = "";


            m_bllFinCheckInvoiceRecordDetailTab_New.TransAdd(modelFinCheckInvoiceRecordDetailTab_New, m_SQLStringList, m_arrayList);
        }
        private void AddFacFeeTab(int nPaidanRegisterTabID)
        {
            //return;
            DataSet ds = m_bllFacFeeTabNew.GetList("FacFeeTabNew.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            DGBY.Model.FacFeeTabNew modelFacFeeTabNew = new DGBY.Model.FacFeeTabNew();

            modelFacFeeTabNew.PaidanRegisterTabID = nPaidanRegisterTabID;





            m_bllFacFeeTabNew.TransAdd(modelFacFeeTabNew, m_SQLStringList, m_arrayList);



        }
        //private void AddFacFeeTab(int nPaidanRegisterTabID)
        //{
        //   // return;
        //    DataSet ds = m_bllFacFeeTab.GetList("FacFeeTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        return;
        //    }

        //    DGBY.Model.FacFeeTab modelFacFeeTab = new DGBY.Model.FacFeeTab();
        //    modelFacFeeTab.FacFeeTabID = m_bllFacFeeTab.GetMaxId();
        //    modelFacFeeTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //    modelFacFeeTab.TCCompDataTabID = 1;
        //    modelFacFeeTab.DZCompDataTabID = 1;
        //    modelFacFeeTab.HKShipCompDataTabID = 1;
        //    modelFacFeeTab.HKTransCompDataTabID = 1;
        //    modelFacFeeTab.DHLDataTabID = 1;
        //    modelFacFeeTab.ZGZQName = "";



        //    m_bllFacFeeTab.TransAddEx(modelFacFeeTab, m_SQLStringList, m_arrayList);


        //    ds = m_bllFeeTab.GetList("");
        //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        DGBY.Model.FacFeeRelationTab modelFacFeeRelationTab = new DGBY.Model.FacFeeRelationTab();
        //        modelFacFeeRelationTab.FacFeeTabID = modelFacFeeTab.FacFeeTabID;

        //        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //        {
        //            int nFeeTabID = Convert.ToInt32(ds.Tables[0].Rows[i]["FeeTabID"].ToString(), 10);

        //            modelFacFeeRelationTab.FeeTabID = nFeeTabID;
        //            m_bllFacFeeRelationTab.TransAdd(modelFacFeeRelationTab, m_SQLStringList, m_arrayList, i);
        //        }
        //    }
        //}
        private void AddFinInvoiceRecordTabNewAfterTrans(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFinInvoiceRecordTab_New.GetList("FinInvoiceRecordTab_New.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }
            Decimal dtBackTaxPoint = 0;
            DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                + nPaidanRegisterTabID.ToString() + "'");
            if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
            {
                dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
            }

            int nFormulaSelector = 0;
            Decimal dtFactorA = 0;
            dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                + nPaidanRegisterTabID.ToString() + "'");
            if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
            {
                dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
                nFormulaSelector = Convert.ToInt32(dsInfo.Tables[0].Rows[0]["公式选择"].ToString(), 10);
                
            }
            //int nBGDComeBackTabID = 0;
            //ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    nBGDComeBackTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGDComeBackTabID"].ToString(), 10);
            //}
            //进出口统一发票
            DGBY.Model.FinInvoiceRecordTab_New modelFinInvoiceRecordTab_New = new DGBY.Model.FinInvoiceRecordTab_New();
            modelFinInvoiceRecordTab_New.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFinInvoiceRecordTab_New.KaiPiaoHuiLv = 0;
            modelFinInvoiceRecordTab_New.KaiPiaoDate = null; 
            modelFinInvoiceRecordTab_New.InvoiceNo = "";
            modelFinInvoiceRecordTab_New.JinE = 0;
            modelFinInvoiceRecordTab_New.ShuiJin = 0;
            modelFinInvoiceRecordTab_New.ChuKouYearMonth = "";
            modelFinInvoiceRecordTab_New.LuDanDate = null;
            modelFinInvoiceRecordTab_New.BackTaxPoint = dtBackTaxPoint;
            modelFinInvoiceRecordTab_New.FactorA = dtFactorA;
            modelFinInvoiceRecordTab_New.FactorB = 1.17M;
            modelFinInvoiceRecordTab_New.PriceTaxFormulaSelector = nFormulaSelector;
            modelFinInvoiceRecordTab_New.JinECheckIgnore = 0;
            modelFinInvoiceRecordTab_New.IsGouHouContractPrint = "否";
            modelFinInvoiceRecordTab_New.IsKaiPiaoFinish = 0;

            m_bllFinInvoiceRecordTab_New.TransAdd(modelFinInvoiceRecordTab_New, m_SQLStringList, m_arrayList);
        }

        private void AddTYInvoiceTabRecAfterTrans(int nPaidanRegisterTabID, int nYSMethodTabID)
        {
          //  DataSet ds = m_bllTYInvoiceTab.ShowTYInvoiceRec("PaidanRegisterTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");
            DataSet ds = m_bllTYInvoiceTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            //int nBGDComeBackTabID = 0;
            //ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    nBGDComeBackTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGDComeBackTabID"].ToString(), 10);
            //}
            //进出口统一发票
            DGBY.Model.TYInvoiceTab modelTYInvoiceTab = new DGBY.Model.TYInvoiceTab();
            modelTYInvoiceTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelTYInvoiceTab.ZhuanYPort = "";
            if (this.comboBoxPort.Text != "东莞")
                modelTYInvoiceTab.JieHuiFSTabID = 1;
            else
                modelTYInvoiceTab.JieHuiFSTabID = 2;
            modelTYInvoiceTab.MaoYiFSTabID = 1;
            modelTYInvoiceTab.Note = "";
            modelTYInvoiceTab.LCNo = "";
            modelTYInvoiceTab.KPDate = System.DateTime.Now;
            modelTYInvoiceTab.BYCompBankCountTabID = 1;
            modelTYInvoiceTab.IsPrint = 0;
            modelTYInvoiceTab.PrintDate = DateTime.Parse("1900-01-01");
            modelTYInvoiceTab.YSMethodTabID = nYSMethodTabID;
            m_bllTYInvoiceTab.TransAdd(modelTYInvoiceTab, m_SQLStringList, m_arrayList);
        }
        private void AddFeeHKYSTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeHKYSTruePayTab.GetListInfo("FeeHKYSTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }



            DGBY.Model.FeeHKYSTruePayTab modelFeeHKYSTruePayTab = new DGBY.Model.FeeHKYSTruePayTab();

            modelFeeHKYSTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeHKYSTruePayTab.BiZhiTabID = 1;
            modelFeeHKYSTruePayTab.ToPubBianHao = "";
            modelFeeHKYSTruePayTab.ToPrivateBianHao = "";
            modelFeeHKYSTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeHKYSTruePayTab.TruePayMonth = 0;
            modelFeeHKYSTruePayTab.ShouldPayMonth = 0;
            //modelFeeHKYSTruePayTab.TruePayMoney = 0;
            modelFeeHKYSTruePayTab.TruePayHuiLv = 0;
            modelFeeHKYSTruePayTab.TruePayMoneyWB = 0;
            modelFeeHKYSTruePayTab.TruePaySXFeeWB = 50;
            modelFeeHKYSTruePayTab.TrueRecvHuiLv = 0;
            modelFeeHKYSTruePayTab.TrueRecvKDFeeRMB = 30;


            //modelFeeHKYSTruePayTab.ToPubFormula = "";
            //modelFeeHKYSTruePayTab.ToPrivateFormula = "";

            modelFeeHKYSTruePayTab.JinBanPerson = "";
            modelFeeHKYSTruePayTab.RecvMonyePerson = "";

            modelFeeHKYSTruePayTab.IsToRecvPayTab = 0;
            modelFeeHKYSTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeHKYSTruePayTab.Note = "";
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;

            modelFeeHKYSTruePayTab.bitFiledReserv1 = false;
            modelFeeHKYSTruePayTab.bitFiledReserv2 = false;

            modelFeeHKYSTruePayTab.stringFiledReserv1 = "";
            modelFeeHKYSTruePayTab.stringFiledReserv2 = "";
            modelFeeHKYSTruePayTab.stringFiledReserv3 = "";
            modelFeeHKYSTruePayTab.stringFiledReserv4 = "";

            modelFeeHKYSTruePayTab.intFiledReserv1 = 0;
            modelFeeHKYSTruePayTab.intFiledReserv2 = 0;
            modelFeeHKYSTruePayTab.intFiledReserv3 = 0;
            modelFeeHKYSTruePayTab.intFiledReserv4 = 0;
            // modelFeeHKYSTruePayTab.intFiledReserv4 = 0;
            modelFeeHKYSTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeHKYSTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeHKYSTruePayTab.decimalFiledReserv1 = 0;
            modelFeeHKYSTruePayTab.decimalFiledReserv2 = 0;
            modelFeeHKYSTruePayTab.decimalFiledReserv3 = 0;
            modelFeeHKYSTruePayTab.decimalFiledReserv4 = 0;

            m_bllFeeHKYSTruePayTab.TransAdd(modelFeeHKYSTruePayTab, m_SQLStringList, m_arrayList);

        }

        private void AddFeeHKCWTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeHKCWTruePayTab.GetListInfo("FeeHKCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTab = new DGBY.Model.FeeHKCWTruePayTab();
            modelFeeHKCWTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];


            modelFeeHKCWTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeHKCWTruePayTab.BiZhiTabID = 1;
            modelFeeHKCWTruePayTab.ToPubBianHao = "";
            modelFeeHKCWTruePayTab.ToPrivateBianHao = "";
            modelFeeHKCWTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeHKCWTruePayTab.TruePayMonth = 0;
            modelFeeHKCWTruePayTab.ShouldPayMonth = 0;
            //modelFeeHKCWTruePayTab.TruePayMoney = 0;
            modelFeeHKCWTruePayTab.TruePayHuiLv = 0;
            modelFeeHKCWTruePayTab.TruePayMoneyWB = 0;
            modelFeeHKCWTruePayTab.TruePaySXFeeWB = 50;
            modelFeeHKCWTruePayTab.TrueRecvHuiLv = 0;
            modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB = 30;


            //modelFeeHKCWTruePayTab.ToPubFormula = "";
            //modelFeeHKCWTruePayTab.ToPrivateFormula = "";

            modelFeeHKCWTruePayTab.JinBanPerson = "";
            modelFeeHKCWTruePayTab.RecvMonyePerson = "";

            modelFeeHKCWTruePayTab.IsToRecvPayTab = 0;
            modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeHKCWTruePayTab.Note = "";
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;

            modelFeeHKCWTruePayTab.bitFiledReserv1 = false;
            modelFeeHKCWTruePayTab.bitFiledReserv2 = false;

            modelFeeHKCWTruePayTab.stringFiledReserv1 = "";
            modelFeeHKCWTruePayTab.stringFiledReserv2 = "";
            modelFeeHKCWTruePayTab.stringFiledReserv3 = "";
            modelFeeHKCWTruePayTab.stringFiledReserv4 = "";

            modelFeeHKCWTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeHKCWTruePayTab.intFiledReserv2 = 0;
            modelFeeHKCWTruePayTab.intFiledReserv3 = 0;
            modelFeeHKCWTruePayTab.intFiledReserv4 = 0;
            modelFeeHKCWTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeHKCWTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeHKCWTruePayTab.decimalFiledReserv1 = 0;
            modelFeeHKCWTruePayTab.decimalFiledReserv2 = 0;
            modelFeeHKCWTruePayTab.decimalFiledReserv3 = 0;
            modelFeeHKCWTruePayTab.decimalFiledReserv4 = 0;

            m_bllFeeHKCWTruePayTab.TransAdd(modelFeeHKCWTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeDLCWTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeDLCWTruePayTab.GetListInfo("FeeDLCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }


            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeDLCWTruePayTab modelFeeDLCWTruePayTab = new DGBY.Model.FeeDLCWTruePayTab();
            modelFeeDLCWTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];



            modelFeeDLCWTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeDLCWTruePayTab.ToPubBianHao = "";
            modelFeeDLCWTruePayTab.ToPrivateBianHao = "";
            modelFeeDLCWTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeDLCWTruePayTab.TruePayMonth = 0;
            modelFeeDLCWTruePayTab.ShouldPayMonth = 0;
            modelFeeDLCWTruePayTab.TruePayMoney = 0;


            modelFeeDLCWTruePayTab.ToPubFormula = "";
            modelFeeDLCWTruePayTab.ToPrivateFormula = "";

            modelFeeDLCWTruePayTab.JinBanPerson = "";
            modelFeeDLCWTruePayTab.RecvMonyePerson = "";

            modelFeeDLCWTruePayTab.IsToRecvPayTab = 0;
            modelFeeDLCWTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeDLCWTruePayTab.Note = "";

            modelFeeDLCWTruePayTab.TruePayMoney = 0;
            modelFeeDLCWTruePayTab.ShouldRecvMoney = 0;

            modelFeeDLCWTruePayTab.bitFiledReserv1 = false;
            modelFeeDLCWTruePayTab.bitFiledReserv2 = false;

            modelFeeDLCWTruePayTab.stringFiledReserv1 = "";
            modelFeeDLCWTruePayTab.stringFiledReserv2 = "";
            modelFeeDLCWTruePayTab.stringFiledReserv3 = "";
            modelFeeDLCWTruePayTab.stringFiledReserv4 = "";

            modelFeeDLCWTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeDLCWTruePayTab.intFiledReserv2 = 3;
            modelFeeDLCWTruePayTab.intFiledReserv3 = 0;
            // modelFeeDLCWTruePayTab.intFiledReserv4 = 0;
            modelFeeDLCWTruePayTab.datetimeFiledReserv1 = DateTime.Parse("1900-01-01");
            modelFeeDLCWTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeDLCWTruePayTab.decimalFiledReserv1 = 0;
            modelFeeDLCWTruePayTab.decimalFiledReserv2 = 0;
            modelFeeDLCWTruePayTab.decimalFiledReserv3 = 0;
            modelFeeDLCWTruePayTab.decimalFiledReserv4 = 0;

            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;
            m_bllFeeDLCWTruePayTab.TransAdd(modelFeeDLCWTruePayTab, m_SQLStringList, m_arrayList);

        }
        //private void AddFeeJCFTruePayTab(int nPaidanRegisterTabID)
        //{
        //    DataSet ds = m_bllFeeJCFTruePayTab.GetList("FeeJCFTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        return;
        //    }



        //    DGBY.Model.FeeJCFTruePayTab modelFeeJCFTruePayTab = new DGBY.Model.FeeJCFTruePayTab();

        //    modelFeeJCFTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //    modelFeeJCFTruePayTab.ToPubBianHao = "";
        //    modelFeeJCFTruePayTab.ToPrivateBianHao = "";

        //    //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
        //    //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
        //    modelFeeJCFTruePayTab.TruePayMonth = 0;
        //    modelFeeJCFTruePayTab.ShouldPayMonth = 0;
        //    modelFeeJCFTruePayTab.ShouldRecvNotRecvMoney = 0;

        //    modelFeeJCFTruePayTab.ToPubFormula = "";
        //    modelFeeJCFTruePayTab.ToPrivateFormula = "";
        //    modelFeeJCFTruePayTab.JCFCompany = "";
        //    modelFeeJCFTruePayTab.JinBanPerson = "";
        //    modelFeeJCFTruePayTab.RecvMonyePerson = "";

        //    modelFeeJCFTruePayTab.IsToRecvPayTab = 0;
        //    modelFeeJCFTruePayTab.IsToFinCheckMoneyTab = 0;
        //    modelFeeJCFTruePayTab.Note = "";
        //    modelFeeJCFTruePayTab.SjDate = System.DateTime.Now.Date;
        //    m_bllFeeJCFTruePayTab.TransAdd(modelFeeJCFTruePayTab, m_SQLStringList, m_arrayList);

        //}
        //private void AddFeeZXZTruePayTab(int nPaidanRegisterTabID)
        //{
        //    DataSet ds = m_bllFeeZXZTruePayTab.GetList("FeeZXZTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        return;
        //    }



        //    DGBY.Model.FeeZXZTruePayTab modelFeeZXZTruePayTab = new DGBY.Model.FeeZXZTruePayTab();

        //    modelFeeZXZTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //    modelFeeZXZTruePayTab.ToPubBianHao = "";
        //    modelFeeZXZTruePayTab.ToPrivateBianHao = "";

        //    //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
        //    //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
        //    modelFeeZXZTruePayTab.TruePayMonth = 0;
        //    modelFeeZXZTruePayTab.ShouldPayMonth = 0;
        //    modelFeeZXZTruePayTab.ShouldRecvNotRecvMoney = 0;

        //    modelFeeZXZTruePayTab.ToPubFormula = "";
        //    modelFeeZXZTruePayTab.ToPrivateFormula = "";
        //    modelFeeZXZTruePayTab.ZXZCompany = "";
        //    modelFeeZXZTruePayTab.JinBanPerson = "";
        //    modelFeeZXZTruePayTab.RecvMonyePerson = "";

        //    modelFeeZXZTruePayTab.IsToRecvPayTab = 0;
        //    modelFeeZXZTruePayTab.IsToFinCheckMoneyTab = 0;
        //    modelFeeZXZTruePayTab.Note = "";
        //    modelFeeZXZTruePayTab.SjDate = System.DateTime.Now.Date;
        //    m_bllFeeZXZTruePayTab.TransAdd(modelFeeZXZTruePayTab, m_SQLStringList, m_arrayList);

        //}
        private void AddFeeDZTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeDZTruePayTab.GetListInfo("FeeDZTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeDZTruePayTab modelFeeDZTruePayTab = new DGBY.Model.FeeDZTruePayTab();
            modelFeeDZTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];


            modelFeeDZTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeDZTruePayTab.DZCompDataTabID = 1;
            modelFeeDZTruePayTab.DZCateTabID = 1;
            modelFeeDZTruePayTab.ToPubBianHao = "";
            modelFeeDZTruePayTab.ToPrivateBianHao = "";
            modelFeeDZTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeDZTruePayTab.TruePayMonth = 0;
            modelFeeDZTruePayTab.ShouldPayMonth = 0;
            //modelFeeDZTruePayTab.TruePayMoney = 0;
            modelFeeDZTruePayTab.DZCounts = 0;
            modelFeeDZTruePayTab.AddPageCounts = 0;



            //modelFeeDZTruePayTab.ToPubFormula = "";
            //modelFeeDZTruePayTab.ToPrivateFormula = "";

            modelFeeDZTruePayTab.JinBanPerson = "";
            modelFeeDZTruePayTab.RecvMonyePerson = "";

            modelFeeDZTruePayTab.IsToRecvPayTab = 0;
            modelFeeDZTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeDZTruePayTab.Note = "";
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;
            modelFeeDZTruePayTab.bitFiledReserv1 = false;
            modelFeeDZTruePayTab.bitFiledReserv2 = false;

            modelFeeDZTruePayTab.stringFiledReserv1 = "";
            modelFeeDZTruePayTab.stringFiledReserv2 = "";
            modelFeeDZTruePayTab.stringFiledReserv3 = "";
            modelFeeDZTruePayTab.stringFiledReserv4 = "";

            modelFeeDZTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeDZTruePayTab.intFiledReserv2 = 0;
            modelFeeDZTruePayTab.intFiledReserv3 = 0;
            modelFeeDZTruePayTab.intFiledReserv4 = 0;
            modelFeeDZTruePayTab.datetimeFiledReserv1 = System.DateTime.Parse("1900-01-01");//送单日期
            modelFeeDZTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeDZTruePayTab.decimalFiledReserv1 = 0;
            modelFeeDZTruePayTab.decimalFiledReserv2 = 0;
            modelFeeDZTruePayTab.decimalFiledReserv3 = 0;
            modelFeeDZTruePayTab.decimalFiledReserv4 = 0;
            m_bllFeeDZTruePayTab.TransAdd(modelFeeDZTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeDHLTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeDHLTruePayTab.GetListInfo("FeeDHLTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeDHLTruePayTab modelFeeDHLTruePayTab = new DGBY.Model.FeeDHLTruePayTab();
            modelFeeDHLTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];



            modelFeeDHLTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeDHLTruePayTab.ToPubBianHao = "";
            modelFeeDHLTruePayTab.ToPrivateBianHao = "";

            //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeDHLTruePayTab.TruePayMonth = 0;
            modelFeeDHLTruePayTab.ShouldPayMonth = 0;
            modelFeeDHLTruePayTab.ShouldRecvNotRecvMoney = 0;

            modelFeeDHLTruePayTab.ToPubFormula = "";
            modelFeeDHLTruePayTab.ToPrivateFormula = "";
            modelFeeDHLTruePayTab.DHLCompany = "DHL";
            modelFeeDHLTruePayTab.JinBanPerson = "";
            modelFeeDHLTruePayTab.RecvMonyePerson = "";

            modelFeeDHLTruePayTab.IsToRecvPayTab = 0;
            modelFeeDHLTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeDHLTruePayTab.Note = "";
            modelFeeDHLTruePayTab.SjDate = System.DateTime.Now.Date;
            modelFeeDHLTruePayTab.DHLCountryTabID = 1;
            modelFeeDHLTruePayTab.bitFiledReserv1 = false;
            modelFeeDHLTruePayTab.bitFiledReserv2 = false;

            modelFeeDHLTruePayTab.stringFiledReserv1 = "";
            modelFeeDHLTruePayTab.stringFiledReserv2 = "";
            modelFeeDHLTruePayTab.stringFiledReserv3 = "";
            modelFeeDHLTruePayTab.stringFiledReserv4 = "";

            modelFeeDHLTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeDHLTruePayTab.intFiledReserv2 = 0;
            modelFeeDHLTruePayTab.intFiledReserv3 = 0;
            modelFeeDHLTruePayTab.intFiledReserv4 = 0;
            modelFeeDHLTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeDHLTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeDHLTruePayTab.decimalFiledReserv1 = 0;
            modelFeeDHLTruePayTab.decimalFiledReserv2 = 0;
            modelFeeDHLTruePayTab.decimalFiledReserv3 = 0;
            modelFeeDHLTruePayTab.decimalFiledReserv4 = 0;
            m_bllFeeDHLTruePayTab.TransAdd(modelFeeDHLTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeBGTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeBGTruePayTab.GetListInfo("FeeBGTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }



            DGBY.Model.FeeBGTruePayTab modelFeeBGTruePayTab = new DGBY.Model.FeeBGTruePayTab();

            modelFeeBGTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeBGTruePayTab.ToPubBianHao = "";
            modelFeeBGTruePayTab.ToPrivateBianHao = "";
            modelFeeBGTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeBGTruePayTab.TruePayMonth = 0;
            modelFeeBGTruePayTab.ShouldPayMonth = 0;
            modelFeeBGTruePayTab.PrivateTruePayMoney = 0;
            modelFeeBGTruePayTab.PubTruePayMoney = 0;

            modelFeeBGTruePayTab.ToPubFormula = "";
            modelFeeBGTruePayTab.ToPrivateFormula = "";

            modelFeeBGTruePayTab.JinBanPerson = "";
            modelFeeBGTruePayTab.RecvMonyePerson = "";

            modelFeeBGTruePayTab.IsToRecvPayTab = 0;
            modelFeeBGTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeBGTruePayTab.Note = "";



            modelFeeBGTruePayTab.bitFiledReserv1 = false;
            modelFeeBGTruePayTab.bitFiledReserv2 = false;

            modelFeeBGTruePayTab.stringFiledReserv1 = "";
            modelFeeBGTruePayTab.stringFiledReserv2 = "";
            modelFeeBGTruePayTab.stringFiledReserv3 = "";
            modelFeeBGTruePayTab.stringFiledReserv4 = "";

            modelFeeBGTruePayTab.intFiledReserv1 = 33;
            modelFeeBGTruePayTab.intFiledReserv2 = 10;
            modelFeeBGTruePayTab.intFiledReserv3 = 0;
            modelFeeBGTruePayTab.intFiledReserv4 = 0;
            modelFeeBGTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeBGTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeBGTruePayTab.decimalFiledReserv1 = 0;
            modelFeeBGTruePayTab.decimalFiledReserv2 = 0;
            modelFeeBGTruePayTab.decimalFiledReserv3 = 0;
            modelFeeBGTruePayTab.decimalFiledReserv4 = 0;

           // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;
            m_bllFeeBGTruePayTab.TransAdd(modelFeeBGTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void buttonAddFillBoxSheet_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                int nPaidanID = Convert.ToInt32(this.comboBoxContractNo.SelectedValue.ToString(), 10);
                if (Frm_Main.m_nEmptyDanID == nPaidanID)
                {
                    MessageBox.Show("合同号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                m_SQLStringList.Clear();
                m_arrayList.Clear();
                int nNewBGPackTabID = m_bllBGPackingTab.GetMaxId();
                DGBY.Model.BGPackingTab modelBGPackingTab = new DGBY.Model.BGPackingTab();

                modelBGPackingTab.BGPackingTabID = nNewBGPackTabID;
                modelBGPackingTab.Note = this.textBoxNote.Text;
                modelBGPackingTab.ShoeBrand = this.textBoxMark.Text;
                modelBGPackingTab.ShipMarks = this.textBoxMaiTou.Text;

                modelBGPackingTab.DingCangNo = this.textBoxSelectShipNo.Text;
                modelBGPackingTab.ShipName = "";
                modelBGPackingTab.HangCi = this.textBoxShipSequence.Text;
                modelBGPackingTab.GuiNo = this.textBoxGoodsBoxNum.Text;
                modelBGPackingTab.FengTiao = this.textBoxClosePaperNo.Text;
                modelBGPackingTab.BGSJPackDJNo = 0;

                modelBGPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";
                modelBGPackingTab.BGPackDJDate = System.DateTime.Now.Date;

                modelBGPackingTab.BGPackDJNo = MakeBGPackDJNo();
                if (this.comboBoxCoinUnit2.SelectedValue != null)
                    modelBGPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
                if (this.comboBoxRecvGoodsComp.SelectedValue != null)
                    modelBGPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
                if (this.comboBoxStartCountry.SelectedValue != null)
                    modelBGPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
                if (this.comboBoxPort.SelectedValue != null)
                    modelBGPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                if (this.comboBoxBGPort.SelectedValue != null)
                    modelBGPackingTab.BGHarborTabID = Convert.ToInt32(this.comboBoxBGPort.SelectedValue.ToString(), 10);
                if (this.comboBoxOutSideCate.SelectedValue != null)
                    modelBGPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);
                if (this.comboBoxContractNo.SelectedValue != null)
                    modelBGPackingTab.PaidanRegisterTabID = Convert.ToInt32(this.comboBoxContractNo.SelectedValue.ToString(), 10);
                if (this.comboBoxBoxCate.SelectedValue != null)
                    modelBGPackingTab.GuiXingTabID = Convert.ToInt32(this.comboBoxBoxCate.SelectedValue.ToString(), 10);
                if (this.comboBoxBGH.SelectedValue != null)
                    modelBGPackingTab.BGHDataTabID = Convert.ToInt32(this.comboBoxBGH.SelectedValue.ToString(), 10);
              
                m_bllBGPackingTab.TransAddEx(modelBGPackingTab, m_SQLStringList, m_arrayList);

                Decimal dtBackTaxPoint = 0;
                DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                    + modelBGPackingTab.PaidanRegisterTabID.ToString() + "'");
                if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                {
                    dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
                }
                Decimal dtFactorA = 0;
                dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                    + modelBGPackingTab.PaidanRegisterTabID.ToString() + "'");
                if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                {
                    dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
                }
               //int nSelectSJPackingTabID = 0;

                DataSet m_ds = m_bllSJCKHTTab.ShowAllCKHTMXForBGZxd("ContractCode = '" + this.comboBoxContractNo.Text + "'");
                if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
                {
                    //nSelectSJPackingTabID = Convert.ToInt32(dsTemp2.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10);
                    //DataSet m_ds = m_bllSJPackGoodsMXTab.GetListByConditionAnother("SJPackGoodsMXTab.SJPackingTabID = '" + nSelectSJPackingTabID + "'");
                    if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < m_ds.Tables[0].Rows.Count; i++)
                        {
                            DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();

                            modelBGPackGoodsMXTab.GoodsMXName = m_ds.Tables[0].Rows[i]["商品名称"].ToString();
                            modelBGPackGoodsMXTab.GGXHZDEtc = m_ds.Tables[0].Rows[i]["质地"].ToString();
                            modelBGPackGoodsMXTab.GGXHZDEtc2 = m_ds.Tables[0].Rows[i]["规格型号"].ToString();
                            modelBGPackGoodsMXTab.FPieceNum = Convert.ToInt32(m_ds.Tables[0].Rows[i]["件数"].ToString(), 10);
                            modelBGPackGoodsMXTab.FNumber = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["数量"].ToString());
                            modelBGPackGoodsMXTab.FMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["毛重"].ToString());
                            modelBGPackGoodsMXTab.FFactWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["净重"].ToString());
                            modelBGPackGoodsMXTab.CKHTDCost = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["单价"].ToString());
                            modelBGPackGoodsMXTab.CKHTJinE = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["金额"].ToString());
                            modelBGPackGoodsMXTab.BGPackingTabID = nNewBGPackTabID;
                            modelBGPackGoodsMXTab.BGSeqNo = Convert.ToInt32(m_ds.Tables[0].Rows[i]["trueSJSeqNo"].ToString()); ;
                            modelBGPackGoodsMXTab.BackTaxPoint = dtBackTaxPoint;
                            modelBGPackGoodsMXTab.FactorA = dtFactorA;
                           // modelBGPackGoodsMXTab.BiZhiTabID = Convert.ToInt32(m_ds.Tables[0].Rows[i]["币制"].ToString(), 10);

                            modelBGPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(m_ds.Tables[0].Rows[i]["单位"].ToString(), 10);

                            m_bllBGPackGoodsMXTab.TransAdd(modelBGPackGoodsMXTab, m_SQLStringList, m_arrayList, i);
                        }
                    }
                }

                int nYSMethodTabID = 10;
                AddOneBGCKContractRec(modelBGPackingTab.PaidanRegisterTabID, false, ref nYSMethodTabID);
                //AddOneBackBGDRec(modelBGPackingTab.PaidanRegisterTabID);
                AddTYInvoiceTabRecAfterTrans(modelBGPackingTab.PaidanRegisterTabID, nYSMethodTabID);
                AddFinInvoiceRecordTabNewAfterTrans(modelBGPackingTab.PaidanRegisterTabID);
                AddFinCheckInvoiceRecordDetailTabNewAfterTrans(modelBGPackingTab.PaidanRegisterTabID);
                AddFacFeeTab(modelBGPackingTab.PaidanRegisterTabID);
                AddFeeBGTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                AddFeeDLCWTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                AddFeeHKCWTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                AddFeeHKYSTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                AddFeeDHLTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                //AddFeeZXZTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                //AddFeeJCFTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                AddFeeDZTruePayTab(modelBGPackingTab.PaidanRegisterTabID);
                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                if (6 != Convert.ToInt32(this.comboBoxBoxCate.SelectedValue) 
                    && 33 != Convert.ToInt32(this.comboBoxBGH.SelectedValue))
                {
                    AddBackRecoveryMaterialResgistInfo(modelBGPackingTab.PaidanRegisterTabID);
                }

                Frm_Main.Log2DB(this.Text, "增加", modelBGPackingTab.BGPackDJNo.ToString());

                ShowFillBoxSheetByContractCode(this.comboBoxContractNo.Text);
                this.checkBoxIsShoe.Checked = false;
                this.textBoxMark.Text = "";
                this.textBoxSelectShipNo.Text = "";
                this.textBoxGoodsBoxNum.Text = "";
                this.textBoxShipSequence.Text = "";
                this.textBoxNote.Text = "";
                this.textBoxClosePaperNo.Text = "";

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
           
        }
        private bool CheckSBDate()
        {
            bool bRet = false;
            if (!Frm_Main.m_bCompleteVer)
            {
                DataSet dsHxdNoTab = m_bllHxdNoTab.GetList("HxdNoTab.PaidanRegisterTabID = '" + this.comboBoxContractNo.SelectedValue + "'");
                if (dsHxdNoTab.Tables.Count > 0 && dsHxdNoTab.Tables[0].Rows.Count > 0)
                {
                    int nHxdNoTabID = Convert.ToInt32(dsHxdNoTab.Tables[0].Rows[0]["HxdNoTabID"].ToString(), 10);
                    DGBY.Model.HxdNoTab modelHxdNoTabOld = m_bllHxdNoTab.GetModel(nHxdNoTabID);
                    int nYear = modelHxdNoTabOld.SBDate.Value.Date.Year;
                    if (nYear != 1900)
                    {
                        bRet = true;
                    }
                }

            }

            return bRet;
        }
        private void buttonModifyFillBoxSheet_Click(object sender, EventArgs e)
        {
            try
            {

                if (CheckSBDate())
                {
                    MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                m_SQLStringList.Clear();
                m_arrayList.Clear();
                DGBY.Model.BGPackingTab modelBGPackingTabOld = m_bllBGPackingTab.GetModel(m_nSelectBGPackingTabID);
                if (modelBGPackingTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

          

                DataSet ds = m_bllBGPackingTab.GetList("BGPackingTab.PaidanRegisterTabID = '" + modelBGPackingTabOld.PaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    //bool bBGHFirst = true;
                    bool bGuiXingFirst = true;
                    bool bDingCangNoFirst = true;
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        int nGuiXingTabID = Convert.ToInt32(ds.Tables[0].Rows[i]["GuiXingTabID"].ToString(), 10);
                        if (nGuiXingTabID != 6)//有一个柜型不为空
                        {
                            bGuiXingFirst = false;
                            break;
                        }
                    }
                    //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    //{
                    //    int nBGHDataTabID = Convert.ToInt32(ds.Tables[0].Rows[i]["BGHDataTabID"].ToString(), 10);
                    //    if (nBGHDataTabID != 33)//有一个柜型不为空
                    //    {
                    //        bBGHFirst = false;
                    //        break;
                    //    }
                    //}
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        string strDingCangNo = ds.Tables[0].Rows[i]["DingCangNo"].ToString();
                        if (strDingCangNo != "")//有一个订舱号不为空
                        {
                            bDingCangNoFirst = false;
                            break;
                        }
                    }
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        int nBGPackingTabIDTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["BGPackingTabID"].ToString(), 10);
                        DGBY.Model.BGPackingTab modelBGPackingTab = m_bllBGPackingTab.GetModel(nBGPackingTabIDTemp);

                        if (m_nSelectBGPackingTabID == nBGPackingTabIDTemp)
                        {
                            modelBGPackingTab.Note = this.textBoxNote.Text;
                            modelBGPackingTab.ShoeBrand = this.textBoxMark.Text;
                            modelBGPackingTab.ShipMarks = this.textBoxMaiTou.Text;

                            
                            modelBGPackingTab.ShipName = "";
                
                            modelBGPackingTab.GuiNo = this.textBoxGoodsBoxNum.Text;
                            modelBGPackingTab.FengTiao = this.textBoxClosePaperNo.Text;


                            modelBGPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";
                            if (!bGuiXingFirst)
                            {
                                if (this.comboBoxBoxCate.SelectedValue != null)
                                    modelBGPackingTab.GuiXingTabID = Convert.ToInt32(this.comboBoxBoxCate.SelectedValue.ToString(), 10);
                            }
                            //if (!bBGHFirst)
                            //{
                            //    if (this.comboBoxBGH.SelectedValue != null)
                            //        modelBGPackingTab.BGHDataTabID = Convert.ToInt32(this.comboBoxBGH.SelectedValue.ToString(), 10);
                            //}
                            if (!bDingCangNoFirst)
                            {
                                modelBGPackingTab.DingCangNo = this.textBoxSelectShipNo.Text;
                            }
                        }

                        modelBGPackingTab.HangCi = this.textBoxShipSequence.Text;
                        if (bDingCangNoFirst)
                            modelBGPackingTab.DingCangNo = this.textBoxSelectShipNo.Text;
                        //if (this.comboBoxContractNo.SelectedValue != null)
                        //modelBGPackingTab.PaidanRegisterTabID = modelBGPackingTabOld.PaidanRegisterTabID;

                        if (modelBGPackingTab.PaidanRegisterTabID != modelBGPackingTabOld.PaidanRegisterTabID)
                        {
                            MessageBox.Show("报关装箱单出现未知错误，请速联系软件作者宋波!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (this.comboBoxCoinUnit2.SelectedValue != null)
                            modelBGPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
                        if (this.comboBoxRecvGoodsComp.SelectedValue != null)
                            modelBGPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
                        if (this.comboBoxStartCountry.SelectedValue != null)
                            modelBGPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
                        if (this.comboBoxPort.SelectedValue != null)
                            modelBGPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                        if (this.comboBoxBGPort.SelectedValue != null)
                            modelBGPackingTab.BGHarborTabID = Convert.ToInt32(this.comboBoxBGPort.SelectedValue.ToString(), 10);
                        if (this.comboBoxOutSideCate.SelectedValue != null)
                            modelBGPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);

                        if (bGuiXingFirst && this.comboBoxBoxCate.SelectedValue != null)
                            modelBGPackingTab.GuiXingTabID = Convert.ToInt32(this.comboBoxBoxCate.SelectedValue.ToString(), 10);

                        if (!string.IsNullOrEmpty(modelBGPackingTab.GuiNo))
                        {
                            int nGuiXingID = m_bllPaiCheTabNew.GetePaiCheGuiXingIDByGuiNo(modelBGPackingTab.GuiNo);
                            if (nGuiXingID > 0 && nGuiXingID != modelBGPackingTab.GuiXingTabID)
                            {
                                MessageBox.Show("柜型与派车管理表设置不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }

                        //if (bBGHFirst && this.comboBoxBGH.SelectedValue != null)
                        //    modelBGPackingTab.BGHDataTabID = Convert.ToInt32(this.comboBoxBGH.SelectedValue.ToString(), 10);
                        if (this.comboBoxBGH.SelectedValue != null)
                            modelBGPackingTab.BGHDataTabID = Convert.ToInt32(this.comboBoxBGH.SelectedValue.ToString(), 10);

                        m_bllBGPackingTab.TransUpdate(modelBGPackingTab, m_SQLStringList, m_arrayList, i);

                    }
                }
                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                if (6 != Convert.ToInt32(this.comboBoxBoxCate.SelectedValue)
                    && 33 != Convert.ToInt32(this.comboBoxBGH.SelectedValue))
                {
                    AddBackRecoveryMaterialResgistInfo(modelBGPackingTabOld.PaidanRegisterTabID);
                }

                Frm_Main.Log2DB(this.Text, "修改", modelBGPackingTabOld.BGPackDJNo.ToString());
                //DGBY.Model.LogRecTab modelLogRecTab = new DGBY.Model.LogRecTab();
                //modelLogRecTab.LogDate = System.DateTime.Now.Date;
                //modelLogRecTab.LogContent = Frm_Main.m_strLoginUser + "修改了合同号"
                //    +  this.comboBoxContractNo.Text + "的报关装箱单";
                //m_bllLogRecTab.Add(modelLogRecTab);

                ShowFillBoxSheetByContractCode(this.comboBoxContractNo.Text);
                MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        
        }

        private void buttonDelFillBoxSheet_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            DGBY.Model.BGPackingTab modelBGPackingTab = m_bllBGPackingTab.GetModel(m_nSelectBGPackingTabID);
            if (modelBGPackingTab == null)
            {
                MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            DGBY.Model.PaidanRegisterTab modelPaidanRegisterTabOld = m_bllPaidanRegisterTab.GetModel(modelBGPackingTab.PaidanRegisterTabID);


            if (Frm_Main.m_nLoginUserId != modelPaidanRegisterTabOld.UserPasswordTabID)
            {
                MessageBox.Show("该合同号不是你派的单，不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                m_bllBGPackingTab.Delete(m_nSelectBGPackingTabID);
                                
                DGBY.Model.LogRecTab modelLogRecTab = new DGBY.Model.LogRecTab();
                modelLogRecTab.LogDate = System.DateTime.Now.Date;
                modelLogRecTab.LogContent = Frm_Main.m_strLoginUser + "删除了合同号"
                    + modelPaidanRegisterTabOld.ContractCode + "的报关装箱单";
                m_bllLogRecTab.Add(modelLogRecTab);

                Frm_Main.Log2DB(this.Text, "删除", modelBGPackingTab.BGPackDJNo.ToString());
                ShowFillBoxSheetByContractCode(this.comboBoxContractNo.Text);
                MessageBox.Show("数据删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.textBoxNote.Text = "";
                this.textBoxSecondSheetNo.Text = "";
                this.textBoxMark.Text = "";
                this.textBoxMaiTou.Text = "";
                this.textBoxSelectShipNo.Text = "";
                //this.textBoxShipName.Text = "";
                this.textBoxShipSequence.Text = "";
                this.textBoxGoodsBoxNum.Text = "";
                this.textBoxClosePaperNo.Text = "";
                return;
            }
        }

        private void checkBoxIsShoe_CheckedChanged(object sender, EventArgs e)
        {

        }


        private void ShowAllMXRecordInDataGridView(int nBGPackingTabID)
        {
            ultraGrid2.DataSource = null;
            DataSet m_ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + nBGPackingTabID + "'");
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                //int nPieceTotal = 0;
                //Decimal nNumTotal = 0;
                //Decimal dtMaoWeight = 0;
                //Decimal dtJingWeight = 0;
                //Decimal dtJinE = 0;
                //for (int i = 0; i < m_ds.Tables[0].Rows.Count; i++)
                //{
                //    nPieceTotal += Convert.ToInt32(m_ds.Tables[0].Rows[i]["件数"].ToString(), 10);
                //    nNumTotal += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["数量"].ToString());
                //    dtMaoWeight += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["毛重"].ToString());
                //    dtJingWeight += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["净重"].ToString());
                //    dtJinE += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["金额"].ToString());
                //}

                //DataRow dr = m_ds.Tables[0].NewRow();
                //dr["件数"] = nPieceTotal;
                //dr["数量"] = nNumTotal;
                //dr["毛重"] = dtMaoWeight;
                //dr["净重"] = dtJingWeight;
                //dr["金额"] = dtJinE;
                //dr["商品名称"] = "合计";
                //m_ds.Tables[0].Rows.Add(dr.ItemArray);

             
               // int a = 0;
                //ultraGrid2.DataSource = m_ds.Tables[0];
                //ultraGrid2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
                //ultraGrid2.DisplayLayout.Bands[0].Columns[1].Hidden = true;

            }
            DataSet ds = m_bllNumDanWeiTab.GetList("");

            this.ultraDropDown1.DataSource = ds.Tables[0];
            this.ultraDropDown1.DisplayMember = "单位名称";
            this.ultraDropDown1.ValueMember = "NumDanWeiTabID";
            this.ultraDropDown1.DisplayLayout.Bands[0].Columns[0].Hidden = true;

            ultraGrid2.DataSource = m_ds.Tables[0];
            ultraGrid2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns[1].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["单价"].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["金额"].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["打折单价"].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["打折金额"].Hidden = true;
            this.ultraGrid2.DisplayLayout.Bands[0].Columns["单位"].ValueList = this.ultraDropDown1;
        }



        private void cellBGPackGoodsMXTabClick()
        {
            //DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = m_bllBGPackGoodsMXTab.GetModel(m_nSelectBGPackGoodsMXTabID);
            //if (modelBGPackGoodsMXTab != null)
            //{
            //    this.textBoxGoodsName.Text = modelBGPackGoodsMXTab.GoodsMXName;
            //    this.textBoxMerial.Text = modelBGPackGoodsMXTab.GGXHZDEtc;
            //    this.textBoxGuiGe.Text = modelBGPackGoodsMXTab.GGXHZDEtc2;
            //    this.textBoxBoxNum.Text = modelBGPackGoodsMXTab.FPieceNum.ToString();
            //    this.textBoxNum.Text = modelBGPackGoodsMXTab.FNumber.ToString();
            //    this.textBoxWeight.Text = modelBGPackGoodsMXTab.FMaoWeight.ToString();
            //    this.textBoxSimpleWeight.Text = modelBGPackGoodsMXTab.FFactWeight.ToString();
            //    this.textBoxSingleCost.Text = modelBGPackGoodsMXTab.CKHTDCost.ToString();
            //    this.textBoxFOB.Text = modelBGPackGoodsMXTab.CKHTJinE.ToString();


            //    if (modelBGPackGoodsMXTab.NumDanWeiTabID != null)
            //        this.comboBoxUnit.SelectedValue = modelBGPackGoodsMXTab.NumDanWeiTabID;
            //}
            //else
            //{
            //    this.textBoxGoodsName.Text = "";
            //    this.textBoxMerial.Text = "";
            //    this.textBoxBoxNum.Text = "";
            //    this.textBoxNum.Text = "";
            //    this.textBoxWeight.Text = "";
            //    this.textBoxSimpleWeight.Text = "";
            //    this.textBoxGuiGe.Text = "";
            //}
        }
        private void CopyBGPackTab(int nPaidanRegisterTabID, long nNewBGDjNo, int nNewBGPackTabID)
        {
            DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackDJNo = '" + this.textBoxSecondSheetNo.Text + "'");
            DateTime dt = System.DateTime.Now.Date;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                int nBGPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);
                DGBY.Model.BGPackingTab modelBGPackingTabOld = m_bllBGPackingTab.GetModel(nBGPackingTabID);
                DGBY.Model.BGPackingTab modelBGPackingTab = new DGBY.Model.BGPackingTab();
                modelBGPackingTab.BGPackingTabID = nNewBGPackTabID;
                modelBGPackingTab.Note = modelBGPackingTabOld.Note;
                modelBGPackingTab.ShoeBrand = modelBGPackingTabOld.ShoeBrand;
                modelBGPackingTab.ShipMarks = modelBGPackingTabOld.ShipMarks;

                modelBGPackingTab.DingCangNo = modelBGPackingTabOld.DingCangNo;
                modelBGPackingTab.ShipName = modelBGPackingTabOld.ShipName;
                modelBGPackingTab.HangCi = modelBGPackingTabOld.HangCi;
                modelBGPackingTab.GuiNo = modelBGPackingTabOld.GuiNo;
                modelBGPackingTab.FengTiao = modelBGPackingTabOld.FengTiao;
                modelBGPackingTab.BGSJPackDJNo = 0;

                modelBGPackingTab.IsShoePack = modelBGPackingTabOld.IsShoePack;
                modelBGPackingTab.BGPackDJDate = dt.Date;

                modelBGPackingTab.BGPackDJNo = nNewBGDjNo;
              
                modelBGPackingTab.BiZhiTabID = modelBGPackingTabOld.BiZhiTabID;
         
                modelBGPackingTab.SHCompTabID = modelBGPackingTabOld.SHCompTabID;
       
                modelBGPackingTab.QYCountryTabID = modelBGPackingTabOld.QYCountryTabID;
         
                modelBGPackingTab.ZYHarborTabID = modelBGPackingTabOld.ZYHarborTabID;
       
                modelBGPackingTab.BZSortTabID = modelBGPackingTabOld.BZSortTabID;
         
                modelBGPackingTab.PaidanRegisterTabID = nPaidanRegisterTabID;
      
         
                modelBGPackingTab.BGHarborTabID = modelBGPackingTabOld.BGHarborTabID;
                //modelBGPackingTab.BGHDataTabID = modelBGPackingTabOld.BGHDataTabID;
                modelBGPackingTab.GuiXingTabID = modelBGPackingTabOld.GuiXingTabID;

                //modelBGPackingTab.GuiXingTabID = 6;
                modelBGPackingTab.BGHDataTabID = 33;
                m_bllBGPackingTab.TransAddEx(modelBGPackingTab, m_SQLStringList, m_arrayList);
            }
            

          
        }
        private void CopyForMXGoodsTab(int nNewBGPackingTabID, Int64 nOldDJNo)
        {
            int nPaidanRegisterTabID = 0;
            DataSet dsTemp = m_bllPaidanRegisterTab.GetAllPaiDanList("ContractCode = '" + this.comboBoxContractNo.Text + "'");
            if (dsTemp.Tables.Count > 0 && dsTemp.Tables[0].Rows.Count > 0)
            {
                nPaidanRegisterTabID = Convert.ToInt32(dsTemp.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
            }
            Decimal dtBackTaxPoint = 0;
            DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                + nPaidanRegisterTabID.ToString() + "'");
            if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
            {
                dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
            }

            Decimal dtFactorA = 0;
            dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                + nPaidanRegisterTabID.ToString() + "'");
            if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
            {
                dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
            }
            DataSet m_ds = m_bllBGPackGoodsMXTab.ShowGoodsMXEx("BGPackingTab.BGPackDJNo = '" + nOldDJNo.ToString() + "'");

     //       DataSet m_ds = m_bllSJCKHTTab.ShowAllCKHTMXForBGZxd("ContractCode = '" + this.comboBoxContractNo.Text + "'");
            DateTime dt = System.DateTime.Now.Date;
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < m_ds.Tables[0].Rows.Count; i++)
                {
                    DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();

                    modelBGPackGoodsMXTab.GoodsMXName = m_ds.Tables[0].Rows[i]["商品名称"].ToString();
                    modelBGPackGoodsMXTab.GGXHZDEtc = m_ds.Tables[0].Rows[i]["质地"].ToString();
                    modelBGPackGoodsMXTab.GGXHZDEtc2 = m_ds.Tables[0].Rows[i]["规格型号"].ToString();
                    modelBGPackGoodsMXTab.FPieceNum = Convert.ToInt32(m_ds.Tables[0].Rows[i]["件数"].ToString(), 10);
                    modelBGPackGoodsMXTab.FNumber = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["数量"].ToString());
                    modelBGPackGoodsMXTab.FMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["毛重"].ToString());
                    modelBGPackGoodsMXTab.FFactWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["净重"].ToString());
                    modelBGPackGoodsMXTab.CKHTDCost = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["单价"].ToString());
                    modelBGPackGoodsMXTab.CKHTJinE = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["金额"].ToString());
                    modelBGPackGoodsMXTab.HMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["打折单价"].ToString());
                    modelBGPackGoodsMXTab.HZMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["打折金额"].ToString());
                    modelBGPackGoodsMXTab.BGPackingTabID = nNewBGPackingTabID;
                    modelBGPackGoodsMXTab.BGSeqNo = Convert.ToInt32(m_ds.Tables[0].Rows[i]["序号"].ToString(), 10);
                    modelBGPackGoodsMXTab.BackTaxPoint = dtBackTaxPoint;
                    modelBGPackGoodsMXTab.FactorA = dtFactorA;
                    //   modelBGPackGoodsMXTab.BiZhiTabID = Convert.ToInt32(m_ds.Tables[0].Rows[i]["币制"].ToString(), 10);

                    modelBGPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(m_ds.Tables[0].Rows[i]["单位"].ToString(), 10);
                    //这里实在无法使用事务，因为此时的BGPackingTabID还没有生成
                    m_bllBGPackGoodsMXTab.TransAdd(modelBGPackGoodsMXTab, m_SQLStringList, m_arrayList, i);
                }
            }
        }
        //这里的复制单据没有增加报关出口合同
        private void buttonCopySheet_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckSBDate())
                {
                    MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                m_SQLStringList.Clear();
                m_arrayList.Clear();

                DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackDJNo = '" + this.textBoxSecondSheetNo.Text + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strContractNo = ds.Tables[0].Rows[0]["合同编号"].ToString();
                    DataSet dsContract = m_bllBGCKHTTab.GetAllBGPackingID(strContractNo);
                    bool bIsDisCount = (bool)dsContract.Tables[0].Rows[0]["isDisCount"];
                    int nPaidanRegisterTabID = 0;
                    DateTime dt = System.DateTime.Now.Date;
                    Int64 n64NewDJNo = MakeBGPackDJNo();
                    DataSet dsTemp = m_bllPaidanRegisterTab.GetAllPaiDanList("ContractCode = '" + this.comboBoxContractNo.Text + "'");
                    if (dsTemp.Tables.Count > 0 && dsTemp.Tables[0].Rows.Count > 0)
                    {
                        int nNewBGPackTabID = m_bllBGPackingTab.GetMaxId();
                        nPaidanRegisterTabID = Convert.ToInt32(dsTemp.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
                        if (Frm_Main.m_nEmptyDanID == nPaidanRegisterTabID)
                        {
                            MessageBox.Show("合同号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        //m_bllBGPackingTab.CopyDJNo(nPaidanRegisterTabID, dt, n64NewDJNo, Convert.ToInt64(this.textBoxSecondSheetNo.Text, 10), this.textBoxGoodsBoxNum.Text, this.textBoxClosePaperNo.Text);
                        CopyBGPackTab(nPaidanRegisterTabID, n64NewDJNo, nNewBGPackTabID);

                        //DataSet ds2 = m_bllBGPackingTab.ShowOneBGPackRec("BGPackDJNo = '" + n64NewDJNo.ToString() + "'");
                        //if (ds2.Tables.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                        //{
                        //    int nBGPackingTabID = Convert.ToInt32(ds2.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);
                        //m_bllBGPackingTab.CopyDJNoForMXGoods(nNewBGPackTabID
                        //   , Convert.ToInt64(this.textBoxSecondSheetNo.Text, 10), m_SQLStringList, m_arrayList);
                        //}
                        CopyForMXGoodsTab(nNewBGPackTabID, Convert.ToInt64(this.textBoxSecondSheetNo.Text, 10));

                        int nYSMethodTabID = 10;
                        AddOneBGCKContractRec(nPaidanRegisterTabID, bIsDisCount, ref nYSMethodTabID);
                        //AddOneBackBGDRec(modelBGPackingTab.PaidanRegisterTabID);
                        int nNewYSMethodTabID = nYSMethodTabID;
                        AddTYInvoiceTabRecAfterTrans(nPaidanRegisterTabID, nNewYSMethodTabID);
                        AddFinInvoiceRecordTabNewAfterTrans(nPaidanRegisterTabID);
                        AddFinCheckInvoiceRecordDetailTabNewAfterTrans(nPaidanRegisterTabID);
                        AddFacFeeTab(nPaidanRegisterTabID);
                        AddFeeBGTruePayTab(nPaidanRegisterTabID);
                        AddFeeDLCWTruePayTab(nPaidanRegisterTabID);
                        AddFeeHKCWTruePayTab(nPaidanRegisterTabID);
                        AddFeeHKYSTruePayTab(nPaidanRegisterTabID);
                        AddFeeDHLTruePayTab(nPaidanRegisterTabID);
                        //AddFeeZXZTruePayTab(nPaidanRegisterTabID);
                        //AddFeeJCFTruePayTab(nPaidanRegisterTabID);
                        AddFeeDZTruePayTab(nPaidanRegisterTabID);
                        m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                        Frm_Main.Log2DB(this.Text, "复制单据号", this.textBoxSecondSheetNo.Text);
                        ShowFillBoxSheetByContractCode(this.comboBoxContractNo.Text);
                        LoggingHelper.Writelog("报关装箱单复制单据，单据号：" + this.textBoxSecondSheetNo.Text); 
                        MessageBox.Show("复制单据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                }
                else
                {
                    MessageBox.Show("该单据号没有对应的报关_装箱单记录，因此无法复制单据，请重新输入单据号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            
        }

        private void buttonExportToExcel_Click(object sender, EventArgs e)
        {

            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
          //  if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];


            string strCompanyName = dt1.Rows[0]["经营单位"].ToString();
            ds = m_bllBYCompanyTab.GetList("CompanyName = '" + strCompanyName + "'");
            DataTable dtComp = ds.Tables[0];
            //DataTable dt = (DataTable)dataGridViewGoodsDetailList.DataSource;
            //DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTab.BGPackDJNo = '" + this.textBoxSecondSheetNo.Text + "'");
            //DataTable dt1 = ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    string templetFile = templetFilePath + "报关_装箱单.xlt";

                    ExcelBase eB = new ExcelBase(templetFile, outFile);

                    try
                    {
                        eB.SeaGateFillBox_DataTableToExcel(dt, dt1, 20, 12, 1, "页", 4, dtComp);
                    }
                    catch (System.Exception ex)
                    {

                    }

                    eB.Close();
                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
           // if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            string strCompanyName = dt1.Rows[0]["经营单位"].ToString();
            ds = m_bllBYCompanyTab.GetList("CompanyName = '" + strCompanyName + "'");
            DataTable dtComp = ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    string templetFile = templetFilePath + "报关_装箱单.xlt";
                    string outFile = "";
                    ExcelBase eB = new ExcelBase(templetFile, outFile);

                    try
                    {
                        eB.SeaGateFillBox_DataTableToExcelAndPrint(dt, dt1, 20, 12, 1, "页", 4, dtComp);
                    }
                    catch (System.Exception ex)
                    {

                    }

                    eB.Close();
                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonPrintPreview_Click(object sender, EventArgs e)
        {
            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
            //if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            string strCompanyName = dt1.Rows[0]["经营单位"].ToString();
            ds = m_bllBYCompanyTab.GetList("CompanyName = '" + strCompanyName + "'");
            DataTable dtComp = ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    string templetFile = templetFilePath + "报关_装箱单.xlt";
                    string outFile = "";
                    ExcelBase eB = new ExcelBase(templetFile, outFile);

                    try
                    {
                        eB.SeaGateFillBox_DataTableToExcelAndPrintPreview(dt, dt1, 20, 12, 1, "页", 4, dtComp);
                    }
                    catch (System.Exception ex)
                    {

                    }


                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void Frm_SeaGateFillBoxSheet_FormClosing(object sender, FormClosingEventArgs e)
        {
            //eB.Close();
        }

        private void buttonSendGoodsPrint_Click(object sender, EventArgs e)
        {
            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
          //  if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    for (int v = 0; v < 1; v++)
                    {
                        string templetFile = templetFilePath + "发货单.xlt";
                        string outFile = "";
                        ExcelBase eB = new ExcelBase(templetFile, outFile);
                        ds = bllTaoDaPrinterNameTab.GetList("");
                        string strPrinterNameTemp = "";
                        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            strPrinterNameTemp = ds.Tables[0].Rows[0]["TaoDaPrinterName"].ToString();
                        }
                        try
                        {
                            eB.OutGoodsSheet_DataTableToExcelAndPrint(dt, dt1, 14, 16, 1, "页", 3, strPrinterNameTemp);
                        }
                        catch (System.Exception ex)
                        {

                        }

                        eB.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonSendGoodsPreview_Click(object sender, EventArgs e)
        {
            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
           // if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    //string templetFile = templetFilePath + "发货单.xlt";
                    //string outFile = "";
                    //ExcelBase eB = new ExcelBase(templetFile, outFile, true);

                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    string templetFile = templetFilePath + "发货单.xlt";

                    ExcelBase eB = new ExcelBase(templetFile, outFile);

                    try
                    {
                        eB.OutGoodsSheet_DataTableToExcel(dt, dt1, 14, 16, 1, "页", 3);
                    }
                    catch (System.Exception ex)
                    {

                    }
                    eB.Close();

                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonInGoodsPrintPreview_Click(object sender, EventArgs e)
        {
            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
           // if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    //string templetFile = templetFilePath + "进货单.xlt";
                    //string outFile = "";
                    //ExcelBase eB = new ExcelBase(templetFile, outFile,true);
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    string templetFile = templetFilePath + "进货单.xlt";

                    ExcelBase eB = new ExcelBase(templetFile, outFile);
                    try
                    {
                        eB.InGoodsSheet_DataTableToExcel(dt, dt1, 14, 16, 1, "页", this.textBoxNoteForJinFa.Text);
                    }
                    catch (System.Exception ex)
                    {

                    }
                    eB.Close();

                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonInGoodsPrint_Click(object sender, EventArgs e)
        {
            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
          //  if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    string templetFile = templetFilePath + "进货单.xlt";
                    string outFile = "";
                    ExcelBase eB = new ExcelBase(templetFile, outFile);
                    ds = bllTaoDaPrinterNameTab.GetList("");
                    string strPrinterNameTemp = "";
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        strPrinterNameTemp = ds.Tables[0].Rows[0]["TaoDaPrinterName"].ToString();
                    }
                    try
                    {
                        eB.InGoodsSheet_DataTableToExcelAndPrint(dt, dt1, 14, 16, 1, "页", this.textBoxNoteForJinFa.Text, strPrinterNameTemp);
                    }
                    catch (System.Exception ex)
                    {

                    }

                    eB.Close();
                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonDetail_Click(object sender, EventArgs e)
        {
            m_dsPaidan = m_bllPaidanRegisterTab.GetNameAndIDAll("");
            if (m_dsPaidan.Tables.Count > 0 && m_dsPaidan.Tables[0].Rows.Count > 0)
            {
                this.comboBoxContractNo.DataSource = m_dsPaidan.Tables[0];
                this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                this.comboBoxContractNo.DisplayMember = "合同编号";
                this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                //if (m_nPaidanRegisterTabID != 0)
                this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                //else
                // this.comboBoxContractNo.SelectedIndex = Frm_Main.m_nContractSelectIndex;
            }
            ShowAllFillBoxSheet("");
            this.ultraGrid1.Dock = DockStyle.Fill;
            this.groupBoxGoodsDetail.Visible = false;
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }



        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);

            InitColumnWidth1();
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;


            string strBGPackingTabID = this.ultraGrid1.Rows[this.ultraGrid1.ActiveCell.Row.Index].Cells[0].Text;
            m_nSelectBGPackingTabID = Convert.ToInt32(strBGPackingTabID, 10);
            cellBGPackingTabClick();
            this.ultraGrid2.Text = "报关装箱单明细(单据编号：" + this.textBoxSecondSheetNo.Text + ")";

            InitColumnWidth1();
        }

        private void InitColumnWidth1()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["单据号"].Width = 90;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["经营单位"].Width = 160;
            ultraGrid1.DisplayLayout.Bands[0].Columns["收货单位"].Width = 130;
            ultraGrid1.DisplayLayout.Bands[0].Columns["起运国"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["装运港"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["包装种类"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["货柜号码"].Width = 90;
            ultraGrid1.DisplayLayout.Bands[0].Columns["柜型"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["封条号"].Width = 90;         
            ultraGrid1.DisplayLayout.Bands[0].Columns["唛头"].Width = 70;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否为鞋的装箱单"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["牌子"].Width = 100;
            ultraGrid1.DisplayLayout.Bands[0].Columns["订航号"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["船名航次"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["报关港"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["报关行"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["备注"].Width = 100;
        }

        private void ultraGrid2_AfterCellActivate(object sender, EventArgs e)
        {
            //int iIndex = this.ultraGrid2.ActiveCell.Row.Index;
            //if (iIndex < 0)
            //    return;
            //string strTemp = this.ultraGrid2.Rows[this.ultraGrid2.ActiveCell.Row.Index].Cells[3].Text;
            //if (strTemp == "合计")
            //    return;
            //string strBGPackGoodsMXTabID = this.ultraGrid2.Rows[this.ultraGrid2.ActiveCell.Row.Index].Cells[0].Text;
            //m_nSelectBGPackGoodsMXTabID = Convert.ToInt32(strBGPackGoodsMXTabID, 10);
            //cellBGPackGoodsMXTabClick();
            m_nDelIndex = ultraGrid2.ActiveRow.Index;

        }

        private void ultraGrid2_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);

            foreach (UltraGridColumn column2 in ultraGrid2.DisplayLayout.Bands[0].Columns)
            {
                string str = column2.Header.Caption;
                if (str == "金额" || str == "单价" || str == "币制" || str == "打折金额" || str == "打折单价")
                {
                    column2.CellAppearance.BackColor = Color.Gray;
                    column2.CellActivation = Activation.ActivateOnly;
                }
            }
            e.Layout.Bands[0].Columns["是否合并"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
            List<string> lstTemp = new List<string>();
            lstTemp.Add("件数");
            lstTemp.Add("数量");
            lstTemp.Add("毛重");
            lstTemp.Add("净重");
            lstTemp.Add("金额");
            //if (Frm_Main.m_bCompleteVer == true)
            //{
            //    lstTemp.Add("打折金额");
            //}

        
            ClassUltraGridCommonSet.SetSumColumn(e, lstTemp);

            InitColumnWidth2();
        }

        private void InitColumnWidth2()
        {
            ultraGrid2.DisplayLayout.Bands[0].Columns["序号"].Width = 40;
            ultraGrid2.DisplayLayout.Bands[0].Columns["是否合并"].Width = 40;
            ultraGrid2.DisplayLayout.Bands[0].Columns["质地"].Width = 120;
            ultraGrid2.DisplayLayout.Bands[0].Columns["规格型号"].Width = 100;
            ultraGrid2.DisplayLayout.Bands[0].Columns["件数"].Width = 40;
            ultraGrid2.DisplayLayout.Bands[0].Columns["数量"].Width = 70;
            ultraGrid2.DisplayLayout.Bands[0].Columns["单位"].Width = 40;
            ultraGrid2.DisplayLayout.Bands[0].Columns["毛重"].Width = 70;
            ultraGrid2.DisplayLayout.Bands[0].Columns["净重"].Width = 70;
            ultraGrid2.DisplayLayout.Bands[0].Columns["币制"].Width = 40;
        }

        private void InitNewAddRowValue(int nIndex)
        {

            UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];

            CurrentUGR.Cells["商品名称"].Value = "";
            CurrentUGR.Cells["质地"].Value = "";
            CurrentUGR.Cells["规格型号"].Value = "";
            CurrentUGR.Cells["件数"].Value = 0;
            CurrentUGR.Cells["是否合并"].Value = 0;
            
            CurrentUGR.Cells["数量"].Value = 0;
            CurrentUGR.Cells["毛重"].Value = 0;
            CurrentUGR.Cells["净重"].Value = 0;
            CurrentUGR.Cells["单位"].Value = 1;

        }
        private bool AddGoodsDetails(int nRowIndex)
        {
            try
            {

                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[nRowIndex];
                //if (ClassInputValid.IsNum(this.errorProvider1, this.textBoxBoxNum))
                //    return;
                //if (ClassInputValid.IsNum(this.errorProvider1, this.textBoxNum))
                //    return;
                //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxWeight))
                //    return;
                //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxSimpleWeight))
                //    return;
                //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxFOB))
                //    return;
                //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxSingleCost))
                //    return;
                int nPaidanRegisterTabID = 0;
                DataSet dsTemp = m_bllPaidanRegisterTab.GetAllPaiDanList("ContractCode = '" + this.comboBoxContractNo.Text + "'");
                if (dsTemp.Tables.Count > 0 && dsTemp.Tables[0].Rows.Count > 0)
                {
                    nPaidanRegisterTabID = Convert.ToInt32(dsTemp.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
                }
                Decimal dtBackTaxPoint = 0;
                DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                    + nPaidanRegisterTabID.ToString() + "'");
                if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                {
                    dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
                }
                Decimal dtFactorA = 0;
                dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                    + nPaidanRegisterTabID.ToString() + "'");
                if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                {
                    dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
                }

                DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();


                modelBGPackGoodsMXTab.GoodsMXName = CurrentUGR.Cells["商品名称"].Value.ToString();
                modelBGPackGoodsMXTab.GGXHZDEtc = CurrentUGR.Cells["质地"].Value.ToString();
                modelBGPackGoodsMXTab.GGXHZDEtc2 = CurrentUGR.Cells["规格型号"].Value.ToString();
                modelBGPackGoodsMXTab.FPieceNum = Convert.ToInt32(CurrentUGR.Cells["件数"].Value.ToString(), 10);
                modelBGPackGoodsMXTab.FNumber = Convert.ToDecimal(CurrentUGR.Cells["数量"].Value.ToString());
                modelBGPackGoodsMXTab.FMaoWeight = Convert.ToDecimal(CurrentUGR.Cells["毛重"].Value.ToString());
                modelBGPackGoodsMXTab.FFactWeight = Convert.ToDecimal(CurrentUGR.Cells["净重"].Value.ToString());

                modelBGPackGoodsMXTab.BackTaxPoint = dtBackTaxPoint;
                modelBGPackGoodsMXTab.FactorA = dtFactorA;
                modelBGPackGoodsMXTab.IsJianShuMerge = Convert.ToInt32(CurrentUGR.Cells["是否合并"].Value.ToString(), 10);

                modelBGPackGoodsMXTab.CKHTDCost = 0;
                modelBGPackGoodsMXTab.CKHTJinE = 0;
                modelBGPackGoodsMXTab.BGPackingTabID = m_nSelectBGPackingTabID;

                if (CurrentUGR.Cells["序号"].Value.ToString() == "")
                {

                    DataSet ds = m_bllBGPackGoodsMXTab.GetBGPackMXMaxSeqNo(m_nSelectBGPackingTabID);
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["MaxBGPackDJNum"].ToString();
                        if (strSJPackingTabIDNo.CompareTo("") == 0)
                            modelBGPackGoodsMXTab.BGSeqNo = 1;
                        else
                        {
                            int nSeqNo = Convert.ToInt32(strSJPackingTabIDNo, 10);
                            modelBGPackGoodsMXTab.BGSeqNo = nSeqNo + 1;
                        }

                    }
                }
                else
                {
                    int nInputSeqNo = Convert.ToInt32(CurrentUGR.Cells["序号"].Value.ToString(), 10);
                    modelBGPackGoodsMXTab.BGSeqNo = nInputSeqNo;
                }


                dsTemp = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGSeqNo = '" + modelBGPackGoodsMXTab.BGSeqNo + "' and BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID.ToString() + "'");
                if (dsTemp.Tables.Count > 0 && dsTemp.Tables[0].Rows.Count > 0)
                {
                    m_bllBGPackGoodsMXTab.BGMoveRecordAfterSeqNo(modelBGPackGoodsMXTab.BGSeqNo, m_nSelectBGPackingTabID);
                }
                else
                {

                }

               // modelBGPackGoodsMXTab.BGSeqNo = Convert.ToInt32(modelBGPackGoodsMXTab.BGSeqNo, 10); ;


                modelBGPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(CurrentUGR.Cells["单位"].Value.ToString(), 10);

                m_bllBGPackGoodsMXTab.Add(modelBGPackGoodsMXTab);

                Frm_Main.Log2DB(this.Text, "增加明细", this.textBoxSecondSheetNo.Text);
                ShowAllMXRecordInDataGridView(m_nSelectBGPackingTabID);
                //MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void buttonGoodsDetailAdd_Click_1(object sender, EventArgs e)
        {
          // AddGoodsDetails(int nRowIndex)
        }
        private void ModifyGoodsDetail(int nRowIndex)
        {
            try
            {
                if (CheckSBDate())
                {
                    MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[nRowIndex];
                m_nSelectBGPackGoodsMXTabID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTabOld = m_bllBGPackGoodsMXTab.GetModel(m_nSelectBGPackGoodsMXTabID);
                if (modelBGPackGoodsMXTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }


                //DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();
                modelBGPackGoodsMXTabOld.BackTaxPoint = modelBGPackGoodsMXTabOld.BackTaxPoint;
                modelBGPackGoodsMXTabOld.FactorA = modelBGPackGoodsMXTabOld.FactorA;
                modelBGPackGoodsMXTabOld.BGPackGoodsMXTabID = m_nSelectBGPackGoodsMXTabID;
                modelBGPackGoodsMXTabOld.GoodsMXName = CurrentUGR.Cells["商品名称"].Value.ToString();
                modelBGPackGoodsMXTabOld.GGXHZDEtc = CurrentUGR.Cells["质地"].Value.ToString();
                modelBGPackGoodsMXTabOld.GGXHZDEtc2 = CurrentUGR.Cells["规格型号"].Value.ToString();
                modelBGPackGoodsMXTabOld.FPieceNum = Convert.ToInt32(CurrentUGR.Cells["件数"].Value.ToString(), 10);
                modelBGPackGoodsMXTabOld.FNumber = Convert.ToDecimal(CurrentUGR.Cells["数量"].Value.ToString());
                modelBGPackGoodsMXTabOld.FMaoWeight = Convert.ToDecimal(CurrentUGR.Cells["毛重"].Value.ToString());
                modelBGPackGoodsMXTabOld.FFactWeight = Convert.ToDecimal(CurrentUGR.Cells["净重"].Value.ToString());
                modelBGPackGoodsMXTabOld.IsJianShuMerge = Convert.ToInt32(CurrentUGR.Cells["是否合并"].Value.ToString(), 10);
                string strDanWei = CurrentUGR.Cells["单位"].Value.ToString();
                if(ClassInputValid.IsNum(strDanWei))
                {
                    modelBGPackGoodsMXTabOld.NumDanWeiTabID = Convert.ToInt32(CurrentUGR.Cells["单位"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllNumDanWeiTab.GetList("NumDanWeiName = '" + strDanWei + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelBGPackGoodsMXTabOld.NumDanWeiTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["NumDanWeiTabID"].ToString(), 10);
                    }
                }

                //modelBGPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(CurrentUGR.Cells["单位"].Value.ToString(), 10);
                modelBGPackGoodsMXTabOld.CKHTJinE = modelBGPackGoodsMXTabOld.CKHTDCost * modelBGPackGoodsMXTabOld.FNumber;
                modelBGPackGoodsMXTabOld.HZMaoWeight = modelBGPackGoodsMXTabOld.HMaoWeight * modelBGPackGoodsMXTabOld.FNumber;

                m_bllBGPackGoodsMXTab.Update(modelBGPackGoodsMXTabOld);
                Frm_Main.Log2DB(this.Text, "修改明细", this.textBoxSecondSheetNo.Text);
                ShowAllMXRecordInDataGridView(modelBGPackGoodsMXTabOld.BGPackingTabID);
                //MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        private void buttonGoodsDetailModify_Click_1(object sender, EventArgs e)
        {
          
        }

        private void buttonGoodsDetailDel_Click_1(object sender, EventArgs e)
        {
          
        }

        private void buttonInsert_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    //if (ClassInputValid.IsNum(this.errorProvider1, this.textBoxBoxNum))
            //    //    return;
            //    //if (ClassInputValid.IsNum(this.errorProvider1, this.textBoxNum))
            //    //    return;
            //    //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxWeight))
            //    //    return;
            //    //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxSimpleWeight))
            //    //    return;
            //    //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxFOB))
            //    //    return;
            //    //if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxSingleCost))
            //    //    return;
            //    DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();

            //    modelBGPackGoodsMXTab.GoodsMXName = this.textBoxGoodsName.Text;
            //    modelBGPackGoodsMXTab.GGXHZDEtc = this.textBoxMerial.Text;
            //    modelBGPackGoodsMXTab.GGXHZDEtc2 = this.textBoxGuiGe.Text;
            //    modelBGPackGoodsMXTab.FPieceNum = Convert.ToInt32(this.textBoxBoxNum.Text, 10);
            //    modelBGPackGoodsMXTab.FNumber = Convert.ToDecimal(this.textBoxNum.Text);
            //    modelBGPackGoodsMXTab.FMaoWeight = Convert.ToDecimal(this.textBoxWeight.Text);
            //    modelBGPackGoodsMXTab.FFactWeight = Convert.ToDecimal(this.textBoxSimpleWeight.Text);

            //    modelBGPackGoodsMXTab.CKHTDCost =0;
            //    modelBGPackGoodsMXTab.CKHTJinE = 0;
            //    modelBGPackGoodsMXTab.BGPackingTabID = m_nSelectBGPackingTabID;

            //    DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + this.textBox1ContractNoGoodsDetail.Text + "'" +
            //        " and BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");

            //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //    {
            //        string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["BGPackingTabID"].ToString();
            //        int nSJPackingTabID = Convert.ToInt32(strSJPackingTabIDNo, 10);

            //    }
            //    else
            //    {
            //        MessageBox.Show("报关_装箱单概况表为空，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        return;
            //    }

            //    ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGSeqNo = '" + this.textBoxSeqNo.Text + "' and BGPackGoodsMXTab.BGPackingTabID = '" + m_nSelectBGPackingTabID.ToString() + "'");
            //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //    {

            //    }
            //    else
            //    {
            //        MessageBox.Show("序号不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        return;
            //    }
            //    m_bllBGPackGoodsMXTab.BGMoveRecordAfterSeqNo(Convert.ToInt32(this.textBoxSeqNo.Text, 10), m_nSelectBGPackingTabID);
            //    modelBGPackGoodsMXTab.BGSeqNo = Convert.ToInt32(this.textBoxSeqNo.Text, 10); ;



            //    if (this.comboBoxUnit.SelectedValue != null)
            //        modelBGPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(this.comboBoxUnit.SelectedValue.ToString(), 10);

            //    m_bllBGPackGoodsMXTab.Add(modelBGPackGoodsMXTab);
            //    ShowAllMXRecordInDataGridView(m_nSelectBGPackingTabID);
            //    //MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //}
        }
        private void SyncContractNo()
        {
            try
            {

                // string str = this.comboBoxContractNo.SelectedValue.ToString();

                int nID = Frm_Main.m_nContractSelectValue;
                //m_nPaidanRegisterTabID = nID;
                DataSet ds = m_bllPaidanRegisterTab.GetList("PaidanRegisterTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nCompId = Convert.ToInt32(ds.Tables[0].Rows[0]["BYCompanyTabID"].ToString(), 10);
                    DataSet ds1 = m_bllBYCompanyTab.GetList("BYCompanyTabID = '" + nCompId + "'");
                    if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                    {
                        this.textBoxCompany.Text = ds1.Tables[0].Rows[0]["经营单位名称"].ToString();
                    }
                }

                string strContractCode = ds.Tables[0].Rows[0]["ContractCode"].ToString();
                ShowFillBoxSheetByContractCode(strContractCode);

                //this.textBoxMark.Text = "";
                //this.textBoxNote.Text = "";


            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }

        private void Frm_SeaGateFillBoxSheet_Activated(object sender, EventArgs e)
        {
            InitContractNoCombox();
            SyncContractNo();
            m_nDelIndex = -1;
        }

        private void Frm_SeaGateFillBoxSheet_Deactivate(object sender, EventArgs e)
        {
            //Frm_Main.m_nContractSelectValue = (int)this.comboBoxContractNo.SelectedValue;
            try
            {
                Frm_Main.m_nContractSelectValue = (int)this.comboBoxContractNo.SelectedValue;

            }
            catch (System.Exception ex)
            {
                //  MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

        private void textBoxNum_TextChanged(object sender, EventArgs e)
        {
            //try
            //{
            //    Frm_Main.WriteLog("textBoxNum_TextChangedBG!");
            //    if (this.textBoxNum.Text != "" && this.textBoxSingleCost.Text != "" && !m_bFlag)
            //    {
            //        Frm_Main.WriteLog("textBoxNum_TextChangedBG!2222");
            //        m_bFlag = true;
            //        int nFPieceNum = Convert.ToInt32(this.textBoxNum.Text, 10);
            //        Decimal dTotalCost = Convert.ToDecimal(this.textBoxSingleCost.Text) * (Decimal)nFPieceNum;
            //        this.textBoxFOB.Text = dTotalCost.ToString();
            //        m_bFlag = false;
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //}
        }

        private void textBoxSingleCost_TextChanged_1(object sender, EventArgs e)
        {
            //try
            //{
            //    Frm_Main.WriteLog("textBoxSingleCost_TextChanged_1BG!");
            //    if (this.textBoxNum.Text != "" && this.textBoxSingleCost.Text != "" && !m_bFlag)
            //    {
            //        Frm_Main.WriteLog("textBoxSingleCost_TextChanged_1!222");
            //        m_bFlag = true;
            //        int nFPieceNum = Convert.ToInt32(this.textBoxNum.Text, 10);
            //        Decimal dTotalCost = Convert.ToDecimal(this.textBoxSingleCost.Text) * (Decimal)nFPieceNum;
            //        this.textBoxFOB.Text = dTotalCost.ToString();
            //        m_bFlag = false;
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //}

        }

        private void textBoxFOB_TextChanged_1(object sender, EventArgs e)
        {
            //try
            //{
            //    Frm_Main.WriteLog("textBoxFOB_TextChanged_1BG!");
            //    if (this.textBoxNum.Text != "" && this.textBoxFOB.Text != "" && !m_bFlag)
            //    {
            //        Frm_Main.WriteLog("textBoxFOB_TextChanged_1BG222!");
            //        m_bFlag = true;
            //        int nFPieceNum = Convert.ToInt32(this.textBoxNum.Text, 10);
            //        if (nFPieceNum > 0)
            //        {
            //            Decimal dSingleCost = Convert.ToDecimal(this.textBoxFOB.Text) / (Decimal)nFPieceNum;
            //            this.textBoxSingleCost.Text = dSingleCost.ToString();
            //        }
            //        m_bFlag = false;

            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //}

        }

        private void checkBoxIsShoe_CheckedChanged_1(object sender, EventArgs e)
        {
            this.textBoxMark.ReadOnly = !this.checkBoxIsShoe.Checked;
            if (!this.checkBoxIsShoe.Checked)
                this.textBoxMark.Text = "";
        }

        private void ultraGrid2_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + this.comboBoxContractNo.Text + "'" +
                 " and BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["BGPackingTabID"].ToString();
                int nSJPackingTabID = Convert.ToInt32(strSJPackingTabIDNo, 10);

            }
            else
            {
                MessageBox.Show("报关_装箱单概况表为空，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid2.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetails(e.Row.Index))
                        e.Cancel = true;



                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid2_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid2.Rows[e.Row.Index].Cells[2].IgnoreRowColActivation = true;
            ultraGrid2.Rows[e.Row.Index].Cells[2].Activation = Activation.AllowEdit;
            ultraGrid2.Rows[e.Row.Index].Cells[2].Activate();
            ultraGrid2.PerformAction(UltraGridAction.EnterEditMode);
            m_bInsertFlag = true;
            InitNewAddRowValue(e.Row.Index);
        }

        private void ultraGrid2_BeforeRowCancelUpdate(object sender, CancelableRowEventArgs e)
        {
            m_bInsertFlag = false;
        }

        private void ultraGrid2_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectSJPackGoodsMXTabID = Convert.ToInt32(ultraGrid2.ActiveRow.Cells[0].Value.ToString(), 10);
                DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTabOld = m_bllBGPackGoodsMXTab.GetModel(nSelectSJPackGoodsMXTabID);
                if (modelBGPackGoodsMXTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {
                        m_bllBGPackGoodsMXTab.Delete(nSelectSJPackGoodsMXTabID);
                        Frm_Main.Log2DB(this.Text, "删除明细", this.textBoxSecondSheetNo.Text);
                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {
                DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + this.comboBoxContractNo.Text + "'" +
     " and BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["BGPackingTabID"].ToString();
                    int nSJPackingTabID = Convert.ToInt32(strSJPackingTabIDNo, 10);

                }
                else
                {
                    MessageBox.Show("报关_装箱单概况表为空，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (CheckSBDate())
                {
                    MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!m_bInsertFlag)
                {

                    UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
                    //row.ParentCollection.Move(row, 0);
                    //this.ultraGrid2.ActiveRowScrollRegion.ScrollRowIntoView(row);
                }
            }
            switch (e.KeyCode)
            {
                case Keys.Up:
                    {
                        UltraGridCell gridCell = this.ultraGrid2.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid2.ActiveCell.Column.Header.Caption;
                        if (strTemp == "单位")
                            return;
                        int nColumnIndex = this.ultraGrid2.ActiveCell.Column.Index;
                        int nIndex = ultraGrid2.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid2.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        UltraGridCell gridCell = this.ultraGrid2.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid2.ActiveCell.Column.Header.Caption;
                        if (strTemp == "单位")
                            return;
                        int nColumnIndex = this.ultraGrid2.ActiveCell.Column.Index;
                        int nIndex = ultraGrid2.ActiveRow.Index;
                        if (nIndex < ultraGrid2.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid2.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid2.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid2.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void toolStripMenuItemAdd_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DataSet ds = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + this.comboBoxContractNo.Text + "'" +
" and BGPackingTabID = '" + m_nSelectBGPackingTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["BGPackingTabID"].ToString();
                int nSJPackingTabID = Convert.ToInt32(strSJPackingTabIDNo, 10);

            }
            else
            {
                MessageBox.Show("报关_装箱单概况表为空，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!m_bInsertFlag)
            {

                UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
                //row.ParentCollection.Move(row, 0);
                //this.ultraGrid2.ActiveRowScrollRegion.ScrollRowIntoView(row);
            }
        }

        private void toolStripMenuItemDel_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                if (ultraGrid2.ActiveRow != null)
                {
                    ultraGrid2.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void ultraGrid2_AfterCellUpdate(object sender, CellEventArgs e)
        {
            if (e.Cell.Column.Key == "单位")
            {
                int nIndex = e.Cell.Row.Index;
                UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];
                string strDanWei = e.Cell.Value.ToString();

                //  string strDanWei = CurrentUGR.Cells["单位"].Value.ToString();
                if (ClassInputValid.IsNum(strDanWei))
                {
                    DataSet ds = m_bllNumDanWeiTab.GetList(" NumDanWeiTabID= '" + strDanWei + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        strDanWei = ds.Tables[0].Rows[0]["单位名称"].ToString();
                        if (strDanWei == "千克")
                            CurrentUGR.Cells["净重"].Value = CurrentUGR.Cells["数量"].Value;
                    }
                }
                else
                {
                    if (strDanWei == "千克")
                        CurrentUGR.Cells["净重"].Value = CurrentUGR.Cells["数量"].Value;
                }
            }
            else if (e.Cell.Column.Key == "数量")
            {
                int nIndex = e.Cell.Row.Index;
                UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];
                if (CurrentUGR.Cells["单位"].Value.ToString() == "千克" || CurrentUGR.Cells["单位"].Value.ToString() == "3")
                    CurrentUGR.Cells["净重"].Value = CurrentUGR.Cells["数量"].Value;
            }
        }

        private void ultraDropDown1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {

        }

        private void AddBackRecoveryMaterialResgistInfo(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllBackRecoveryMaterialResgistTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                return;

            DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = m_bllPaidanRegisterTab.GetModel(nPaidanRegisterTabID);
            if (null != modelPaidanRegisterTab)
            {
                DGBY.Model.BYBackQingDanTab modelBYBackQingDanTab = m_bllBYBackQingDanTab.GetModel(modelPaidanRegisterTab.BYBackQingDanTabID);
                if (null != modelBYBackQingDanTab)
                {
                    DGBY.Model.DG_BackRecoveryMaterialResgistTab modelBackRecoveryMaterialResgistTab = new DGBY.Model.DG_BackRecoveryMaterialResgistTab();

                    modelBackRecoveryMaterialResgistTab.PaidanRegisterTabID = nPaidanRegisterTabID;
                    if (modelBYBackQingDanTab.IsTidan)
                    {
                        modelBackRecoveryMaterialResgistTab.td = 1;
                    }
                    else
                    {
                        modelBackRecoveryMaterialResgistTab.td = 2;
                    }

                    if (modelBYBackQingDanTab.IsRCD)
                    {
                        modelBackRecoveryMaterialResgistTab.rcd = 1;
                    }
                    else
                    {
                        modelBackRecoveryMaterialResgistTab.rcd = 2;
                    }

                    if (modelBYBackQingDanTab.IsLLD)
                    {
                        modelBackRecoveryMaterialResgistTab.lld = 1;
                    }
                    else
                    {
                        modelBackRecoveryMaterialResgistTab.lld = 2;
                    }

                    if (modelBYBackQingDanTab.IsTYD)
                    {
                        modelBackRecoveryMaterialResgistTab.tyd = 1;
                    }
                    else
                    {
                        modelBackRecoveryMaterialResgistTab.tyd = 2;
                    }

                    if (modelBYBackQingDanTab.IsFXT)
                    {
                        modelBackRecoveryMaterialResgistTab.fxt = 1;
                    }
                    else
                    {
                        modelBackRecoveryMaterialResgistTab.fxt = 2;
                    }

                    if (modelBYBackQingDanTab.IsWTS)
                    {
                        modelBackRecoveryMaterialResgistTab.wts = 1;
                    }
                    else
                    {
                        modelBackRecoveryMaterialResgistTab.wts = 2;
                    }

                    modelBackRecoveryMaterialResgistTab.ckht = 1;

                    modelBackRecoveryMaterialResgistTab.bCannotRecover = false;
                    modelBackRecoveryMaterialResgistTab.IsLock = false;
                    m_bllBackRecoveryMaterialResgistTab.Add(modelBackRecoveryMaterialResgistTab);
                }
            }
        }    
    }
}